Serilog 无法显示输出日志 aspnetcore 2.1 vs 2017

Serilog cannot show output logs aspnetcore 2.1 vs 2017

我正在使用 aspnetcore core 2.1 编写一些 webapi 我想使用 serilog,但我找不到一个简单的例子可以给我一个起点并告诉我我需要做什么。

我想做以下事情

        Log.Logger = new LoggerConfiguration()
                     .ReadFrom.Configuration(Configuration)
                     .Enrich.FromLogContext()
                     .WriteTo.ColoredConsole()
                     .WriteTo.Console()
                      .CreateLogger();


        Log.Verbose("This is a verbose statement");
        Log.Debug("This is a debug statement");
        Log.Information("This is a info statement");
        Log.Warning("This is a warning statement");
        Log.Error(new IndexOutOfRangeException(), "This is an error statement");
        Log.Fatal(new AggregateException(), "This is an fatal statement");

Appsetting 文件设置 serilog

    {
      "Serilog": {
        "MinimumLevel": {
          "Default": "Information",
          "Override": {
            "Microsoft": "Warning",
            "System": "Warning"
          }
        },
        "WriteTo": [
          {
            "Name": "[ColoredConsole]",
            "Args": {"outputTemplate": "[{Timestamp:HH:mm:ss.fff}] {Level:u3} - {Message}{NewLine}{Exception}"}
          },
           "WriteTo": [
          {
            "Name": "console",
            "Args": {"outputTemplate": "[{Timestamp:HH:mm:ss.fff}] {Level:u3} - {Message}{NewLine}{Exception}"}
          },
          {
            "Name": "RollingFile",
            "Args": {
              "pathFormat": "logs\log-{Date}.log",
              "outputTemplate": "[{Timestamp:dd/MM/yy HH:mm:ss.fff z}] {Level:u3} {Message}{NewLine}{Exception}"
            }
          }
        ]
      },

我哪里错了?

谢谢

您始终可以从复制找到的示例应用程序开始 here。它将帮助您完成部分工作,然后您需要做的就是添加您需要的特定接收器。