AspNetCore-Serilog-错误地记录到IISExpress文件夹

时间:2019-01-14 13:36:07

标签: c# asp.net-core .net-core serilog

从两个屏幕快照中可以看到,我在相同的解决方案中有两个服务,但是在不同的项目中它们的配置设置都相同,但是出于某种原因,它们登录到两个不同的位置。

Logs to IISExpress Folder Relative Logging

AppSettings.json

 {   
      "Logging": {
        "LogLevel": {
          "Default": "Debug"
        }
        },
        "AllowedHosts": "*",
        "Serilog": {
          "MinimumLevel": {
            "Default": "Debug"
          },
          "WriteTo": [
            {
              "Name": "File",
              "Args": {
                "path": "./logs/.log",
                "rollingInterval": "Day"
              }
            }
          ]
        }
      }

Startup.cs

public Startup(IHostingEnvironment env)
{
    var builder = new ConfigurationBuilder()
        .SetBasePath(env.ContentRootPath)
        .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
        .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
        .AddEnvironmentVariables();
    Configuration = builder.Build();

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

只想登录到相对日志文件夹即可。

最后,我可以做的任何改进,然后告诉我。

0 个答案:

没有答案