net5使用serilog插件

nuget安装serilog相关插件,有很多,我这里只安装了下面这几个,别的自己慢慢再研究:

配置文件中,进行必要的配置:

 把Serilog添加到依赖注入容器中:

最后一步进行测试:

 

 附:appsetting.json中Serilog节点完整内容(包含对系统日志的过滤)

   "Serilog": {
      "MinimumLevel": {
      "Default": "Information",
      "Override": {
        "Microsoft": "Warning",
        "System": "Information"
      }
    },
    "WriteTo": [
      {
        "Name": "File",
        "Args": {
          "path": "Logs/log.txt",
          "rollingInterval": "Day"
        }
      },
      {
        "Name": "Console",
        "Args": {}
      }
    ]
  }
原文地址:https://www.cnblogs.com/lishidefengchen/p/14511033.html