使用Serilog进行ASP.NET Core日志记录

时间:2017-10-24 13:49:19

标签: c# asp.net-core serilog

我试图理解为什么我的应用程序在从visual studio和/或IIS下执行时不会记录相同数量的信息。

这是我与日志记录相关的启动代码(构造函数):

Log.Logger = new LoggerConfiguration()
    .ReadFrom.Configuration( Configuration )
    .CreateLogger();

然后在Configure方法

public void Configure( IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory ) {
    loggerFactory.AddSerilog();

}

最后,您可以找到appsettings.json配置文件的摘录

"Serilog": {
    "Using": [ "Serilog.Sinks.RollingFile" ],
    "MinimumLevel": {
        "Default": "Verbose",
        "Override": {
            "Microsoft": "Error",
            "Microsoft.AspNetCore.Identity": "Debug",
            "IdentityServer4": "Verbose",
            "IdentityModel": "Verbose",
            "System": "Warning",
            "Serilog": "Verbose"
        }
    },
    "WriteTo": [
        {
            "Name": "RollingFile",
            "Args": {
                "pathFormat": "AppLogs/logger-{Date}.log",
                "outputTemplate": "{Timestamp:o} [{Level:u3}] ({Application}/{MachineName}/{ThreadId}) {Message}{NewLine}{Exception}",
                "fileSizeLimitBytes": 16384
            }
        },
        {
            "Name": "LiterateConsole"
        }
    ],
    "Enrich": [ "FromLogContext", "WithMachineName", "WithThreadId" ],
    "Properties": {
        "Application": "Sample"
    }
},

创建了日志文件,但文件中的信息与我在控制台输出中看到的信息不同。 我缺少什么?

0 个答案:

没有答案