Search code examples
asp.net-mvcazureappinsights

How to I read and write to console in Azure in .Net framework over a long period of time?


We have a .net framework 4.5.1 MVC web application. We want to log information to the console when the application runs. Obviously when running the app in my local computer, I can see the output window and my logs are there. But what about when it's deployed to Azure? How do I see my logs? Where in Azure should I log to (or what are my options)?

I tried:

  • Log streaming, but that lets me read logs for 12 hours then auto-shuts off. I need to see logs from a long time ago.
  • Azure App Insights, but I couldn't find any log information in there.
  • Log Querying, where it shows me a SQL-studio-like interface. But it says there's no logs, and sometimes it's grayed out and I can't enter a query, not that it shows anyways.
  • Using these logging tools:
Console.WriteLine("🔥 Console.WriteLine");
System.Diagnostics.Trace.WriteLine("🔥 Trace.WriteLine");
System.Diagnostics.Trace.TraceInformation("🔥 Trace.TraceInformation");
System.Diagnostics.Trace.TraceWarning("🔥 Trace.TraceWarning");
System.Diagnostics.Trace.TraceError("🔥 Trace.TraceError");

But I can't find my logs anywhere except in log streaming, which isn't what I'm looking for since that only works for 12 hours.


Solution

  • I tried to repro in my local and i can able to see my logs through:

    . Enable diagnostics

    .Download Logs from Kudu console

    From Diagnostic setting i have enabled the following to see the logs

    enter image description here

    enter image description here

    From Application insight we can see below data for our application enter image description here

    And , Using KuduConsole we can download the log files . From app service >advance tools> click on GO

    enter image description here

    After open kudu Go to **Debug console** and from here we can download our logs from the Left side as marked:

    enter image description here

    But I can't find my logs anywhere except in log streaming, which isn't what I'm looking for since that only works for 12 hours.

    Also Thanks to Amit Apple posting your suggestion as an answer to help other community members.

    "You can do this by setting an App setting called DIAGNOSTICS_TEXTTRACETURNOFFPERIOD to a value (much) greater than 12 * 60 * 60 * 1000 which is 12 hours in milliseconds." as mentioned in GItHub

    For further information Please refer this SO thread How can I view console or trace output in an azure app service? Console.WriteLine or Trace.TraceError