Today I was developing an Web APP and it was giving an error after I host it on Azure. To understand the error I have log the traces. Here is the way that explains that how we can do that.
We can directly use Trace class (System.Diagnostics.Trace) for write the logs. I have written the below piece of the code as a first line in the method.
System.Diagnostics.Trace.WriteLine(“I am getting called…”);
Now navigate to your Azure Account –> The app service where you have deployed the Web APP –> Diagnostics Logs.
You have something called “Application Logging (Filesystem)” and you can switch it on. There are four options available there.
Error – Error, Critical
Warning – Warning, Error, Critical
Information – Info, Warning, Error, Critical
Verbose – Trace, Debug, Info, Warning, Error, Critical (all categories)
I normally prefer Verbose as it gives everything.
Now, browse the URL for hitting the action where you have written the tracing.
Navigate to Advance Tools under you AppService and Click on Go
It opens a new tab as below – Click on Debug console and then CMD.
You will see the below screen, click on LogFiles –> Application, you will see the .txt file. Click on Edit icon to see the logs.
Note : For Application logging, you can turn on the file system option temporarily for debugging purposes. This option turns off automatically in 12 hours