Question

I have a .Net back end mobile service and I would like my System.Diagnostics.Trace statements to go to the same destination as ApiServices.Log (i.e. the portal).

The reason for this is that I don't want to pass ITraceWriter down to my data tier due to the dependencies it adds (System.Web.Http etc).

I started to look at an approach where I would add to the trace listeners collection, similar to as described here:

http://blog.tylerdoerksen.com/2012/04/20/logging-in-azure-part-3-traceevent-logs/

But this adds an instance of DiagnosticMonitorTraceListener which doesn't exist by default in a MobileService as this lives in Microsoft.WindowsAzure.Diagnostics.

Does anyone know how to do this?

Thanks

F

Was it helpful?

Solution

In general, trace messages are written to the logs regardless of where they come from. For example, if I have a custom controller like this:

    public string Get()
    {
        IHubContext hubContext = Services.GetRealtime<ChatHub>();

        Trace.WriteLine("something!");
        Trace.TraceError("error");
        Trace.TraceInformation("info");


        hubContext.Clients.All.hello("Hello Chat Hub clients from custom controller!");
        return "Hello from custom controller!";
    }

then "error" and "info" are written as you would expect. In fact, you can find the logs directly from within VS by using the Service Explorer and then Azure and Mobile Services. Right click on your service and select View Logs.

The only wrinkle is that verbose messages are not written as the default log level is Info. You can work around this by setting the level manually through the Kudu site:

https://.scm.azure-mobile.net

Then under the "Debug Console" drill down to Site/diagnostics and edit the file settings.json. It should look something like this:

"AzureDriveEnabled":true,"AzureDriveTraceLevel":"Information","AzureTableEnabled":false,"AzureTableTraceLevel":"Error","AzureBlobEnabled":false,"AzureBlobTraceLevel":"Error"}

Change the Information value to Verbose and you will get verbose messages as well.

Hope this helps!

Henrik

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top