Logging .net core web api with azure

Tanul 811 Reputation points


I need to host a .net core web api as app service in azure. Is it mandatory to enable file system option to view console logs. This option will any way work for 12 hours and not recommended in production then how could we see our logs. I have used only console log provider in my application. Is there any way to view logs on some console rather than saving in the file.

How can we get the console like in linux based systems or kubernetes.

Thank you

Azure App Services
Azure App Services
A feature of Azure App Service used to create and deploy scalable, mission-critical web apps.
4,555 questions
.NET Runtime
.NET Runtime
.NET: Microsoft Technologies based on the .NET software framework.Runtime: The period of time during which a program is being executed in a computer.
979 questions
1 vote

Accepted answer
  1. ajkuma 14,086 Reputation points Microsoft Employee

    @Tanul , With the curl itself, you can scope the live traces to any providers/folders, you may additional specify the path.

    Kudu service (as well as its application) write traces to the /Logfiles folder. The logstream endpoint (/logstream in the Kudu service) enables you to view with any real time traces as they are being written.

    /api/logstream/kudu/trace => kudu related traces intended for diagnostic kudu issues.
    /api/logstream/kudu/deployment => kudu deployment traces intended for application developers/operators.
    /api/logstream/application => application traces.
    /api/logstream/http => iis logs.

    Kindly see this Diagnostic Log Stream for more details.

    Yes, you can change DIAGNOSTICS_TEXTTRACETURNOFFPERIOD to a value greater than 12 hours (12 * 60 * 60 * 1000 in milliseconds) based on your requirement (considering the space).

4 additional answers

Sort by: Most helpful
  1. ajkuma 14,086 Reputation points Microsoft Employee

    @Tanul , Just to add more clarity

    Failure to disable the stdout log can lead to app or server failure. There's no limit on log file size or the number of log files created. So it is recommended to only use stdout logging to troubleshoot app startup problems and disable stdout logging when troubleshooting is complete by setting stdoutLogEnabled="false".

    For general logging in an ASP.NET Core app after startup, use a logging library that limits log file size and rotates logs. For more information, see third-party logging providers.
    We avoid any feature that involves writing to the app's file system in a continuous manner, which can degrade performance.

    Kindly refer Logging in .NET Core and ASP.NET Core doc for more details.

  2. ajkuma 14,086 Reputation points Microsoft Employee

    @Tanul ,

    You're limited to a maximum of 100 megabytes of logs when you use the file system. (File system logs are only for short-term retention. Azure deletes old log files to make room for new ones after the limit is reached.)

    In cases when configuring logs to go to File System/, they go to a different LogFiles folder: D:\home\LogFiles\SiteExtensions\Kudu. If you need to stream them, you can run (log in with your deployment credentials):

    curl https://{app}.scm.azurewebsites.net/api/logstream/SiteExtensions/Kudu -u YourDeploymentUser  

    Or if using Azure site log tail (which wraps the same API), pass -p SiteExtensions/Kudu to tell it to stream from that path.

    Timeout in milliseconds to keep application logging on (Default is 43200000, which is 12 hours) is on the app:

  3. Tanul 811 Reputation points

    @ajkuma , Please correct me if I'm wrong. So we've 2 options here. Save the log files let say using any 3rd party logger in some folder for eg. D:\home\LogFiles\somedirectory\mylogs

    Now, if we need to access it then we can open kudu portal and check the logs manually.

    Secondly, if we need to use the azure log stream feature for STDOUT logs then firstly, we have to enable azure application log file system option. To increase that default 12 hours period we have to create this variable in app settings and specify the value.


    And, once the time expires I have to manually enable it again.

    If we need to access stdout logs then we can fire the curl command like this or use log stream tab in azure(default place for logs is D:\home\LogFiles\SiteExtensions\Kudu)

     curl https://{app}.scm.azurewebsites.net/api/logstream/SiteExtensions/Kudu/ -u YourDeploymentUser  

    Am I correct here or mixed-up the steps. Could you please confirm.

  4. JoyDutt 806 Reputation points

    Hi @Tanul

    You can try enabling logging features and later use Kudo to view logs.Some minor cost for using storage to store file but still you can always limit.

    Azure Monitor integration to route your logs to an Azure Storage Account or Log Analytics workspace. Persisting all logs on the file system indefinitely would fill your app’s file system eventually.


    Kudo Steps :: https://learn.microsoft.com/en-us/learn/modules/capture-application-logs-app-service/

    (Please don’t forget to "Accept the answer" and “up-vote” wherever the information provided helps you, this can be beneficial to other community members. Thank You)


    Disclaimer: This posting is provided "AS IS" with no warranties or guarantees, and confers no rights.