Log event datetime with.Net Core Console logger

后端 未结 3 1728
抹茶落季
抹茶落季 2021-02-18 13:33

I\'m using logging to Console output, that built-in to .Net Core framework. Here initialization of the logger:

var serviceCollection = new ServiceCollection();
s         


        
3条回答
  •  佛祖请我去吃肉
    2021-02-18 14:03

    Example in .NET 5 (ASP.NET Core):

    public void ConfigureServices(IServiceCollection services)
    {
        services.AddLogging(options =>
        {
            options.AddSimpleConsole(c =>
            {
                c.TimestampFormat = "[yyyy-MM-dd HH:mm:ss] ";
                // c.UseUtcTimestamp = true; // something to consider
            });
        });
    
        // ...
    }
    

    Output example:

    [2020-12-13 12:55:44] info: Microsoft.Hosting.Lifetime[0] Application is shutting down...
    

提交回复
热议问题