为什么即使我已经完成配置,Serilog也不起作用

时间:2020-09-28 03:45:31

标签: c# serilog

我已经在program.cs中进行了配置,并安装了所有软件包,但无法正常工作。

var configuration = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json")
.Build();
Log.Logger = new LoggerConfiguration()
.ReadFrom.Configuration(configuration)
.WriteTo
.Map("0", "Other-Other", (name, wt) => wt.File($"C:\\Serilog\\{name.Split('-')[0]}\\{name.Split('-')[1]}.txt", rollingInterval: RollingInterval.Day))
.CreateLogger();

我使用的日志行-

 logger.LogInformation("\n Start InsertPRAsync Method.");

1 个答案:

答案 0 :(得分:0)

尝试在.UseSerilog()方法中将CreateDefaultBuilder()添加到CreateHostBuilder(),如下所示:

来自Serilog.AspNetCore Documentation

的示例
Host.CreateDefaultBuilder(args)
    .UseSerilog() // <-- Add this line
    .ConfigureWebHostDefaults(webBuilder =>
    {
        webBuilder.UseStartup<Startup>();
    });