Asp.net Core azure web app logging

后端 未结 2 1340
既然无缘
既然无缘 2021-01-07 05:02

I have an asp.net core deployed to azure, and I am trying to configure logging to my application using the Microsoft.Extentions.Logging interfaces.

curr

相关标签:
2条回答
  • 2021-01-07 05:24

    First of all you have to configure logs in your application on Azure:

    There is also an option to look at the application console output:

    You can also configure Storage on Azure and save logs there (you can configure that in Diagnostic logs section).

    0 讨论(0)
  • 2021-01-07 05:32

    If you want to use the Log Stream in an easy way in Azure, you can do this:

    public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory)
    {
        var sourceSwitch = new SourceSwitch("DefaultSourceSwitch");
        sourceSwitch.Level = SourceLevels.Information;
        loggerFactory.AddTraceSource(sourceSwitch, new TextWriterTraceListener(writer: Console.Out));
    }
    

    TraceListener will ensure that your logs will go to the standard trace output. You also need to enable stdoutLogEnabled in the web.config (set it to true).

    <aspNetCore stdoutLogEnabled="true" />
    

    If you do these two things, you will see all your logs and system logs as well in the LogStream. You can control the level yourself.

    P.S. This will work only on Full .NET Framework

    P.P.S. I think if you turn on logging to blob under Diagnostic logs setting in Azure, you can have it saved to blob. So everything will happen without you writing any code and manually writing to some location.

    0 讨论(0)
提交回复
热议问题