ASP.NET web application in Azure - How to log errors? ASP.NET web application in Azure - How to log errors? azure azure

ASP.NET web application in Azure - How to log errors?


I am afraid just throwing an exception doesn't work in Azure Web application logging.

ASP.NET applications can use the System.Diagnostics.Trace class to log information to the application diagnostics log. The four methods in example below correspond with the diagnostic log levels:

Trace.TraceError("Message"); // Write an error message   Trace.TraceWarning("Message"); // Write a warning messageTrace.TraceInformation("Message"); // Write an information messageTrace.WriteLine("Message"); // Write a verbose message

enter image description here

Besides the basic information for logged events, blob storage log additional information such as the instance ID, thread ID, and a more granular timestamp (tick format) in CSV.

enter image description here

A great article here about logging tips and tools.

See also the Reference to the official Azure Web Apps Logging Document.


On Azure Websites, best way to log would be Application Insights, you can use free version to get insights about crashes/speed/performance.

However, Application Insights is little slower if you enable everything. But if you customize it and enable only error logging, it would push all logs to your azure application insights account and you will be able to monitor/analyze it very nicely.

For more details:https://azure.microsoft.com/en-in/documentation/articles/app-insights-api-custom-events-metrics/

Instead of automatically configuring Application Insights, I would suggest, take an empty project, setup application insights. Notice all added config files and nuget packages. There is some insight config file, except application key/signature, you can turn off everything.

Only when you want to track an exception manually, you can create TelemetryClient and call TrackException method. You can pass more details if you need.