首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >检查Serilog是否配置正确

检查Serilog是否配置正确
EN

Stack Overflow用户
提问于 2022-05-11 19:07:13
回答 1查看 460关注 0票数 -1

在我的subloggers应用程序中,我设置了一个Serilog,用于将不同类型的事件(信息、警告等)记录到带有子记录器的Server数据库中的不同表中,并且所有事件都进入一个文件。

文件日志记录工作正常,但Server日志记录工作不正常。数据库中的专用表正在自动创建,但没有任何内容被写入其中。我在连接到数据库时使用sa登录,所以这与角色和权限无关。

我目前的配置如下:

代码语言:javascript
复制
"WriteTo": [
  {
    "Name": "Debug",
    "Args": {
      "outputTemplate": "[{Timestamp:HH:mm:ss}] [{Level:u3}] {Message:l} {NewLine}"
    }
  },
  {
    "Name": "File",
    "Args": {
      "Path": "D:/file.txt",
      "rollingInterval": "Day",
      "outputTemplate": "[{Timestamp:HH:mm:ss}] [{Level:u3}] {Message:l} {NewLine}"
    }
  },
  {
    "Name": "Logger",
    "Args": {
      "configureLogger": {
        "Filter": [
          {
            "Name": "ByIncludingOnly",
            "Args": {
              "expression": "(@Level = 'Error' or @Level = 'Fatal')"
            }
          }
        ],
        "WriteTo": [
          {
            "Name": "MSSqlServer",
            "Args": {
              "connectionString": "Data Source=.\\SQLEXPRESS;User Id=sa;Password=*****; Initial Catalog=LogsDb",
              "tableName": "NmsRecipesLogs_Errors",
              "autoCreateSqlTable": true,
              "batchPostingLimit": 1,
              "columnOptionsSection": {
                "removeStandardColumns": [ "MessageTemplate", "Properties" ]
              }
            }
          }
        ]
      }
    }
  },
  {
    "Name": "Logger",
    "Args": {
      "configureLogger": {
        "Filter": [
          {
            "Name": "ByIncludingOnly",
            "Args": {
              "expression": "(@Level = 'Information' or @Level = 'Warning')"
            }
          }
        ],
        "WriteTo": [
          {
            "Name": "MSSqlServer",
            "Args": {
              "connectionString": "Data Source=.\\SQLEXPRESS;User Id=sa;Password=****;Initial Catalog=LogsDb",
              "tableName": "NmsRecipesLogs_Info",
              "autoCreateSqlTable": true,
              "batchPostingLimit": 1,
              "columnOptionsSection": {
                "removeStandardColumns": [ "MessageTemplate", "Properties" ]
              }
            }
          }
        ]
      }
    }
  }
]

我知道MSSQLServer接收器不会立即将日志写入数据库,所以我将batchPostingLimit设置为1,但没有任何效果。

问题是如何确保应用程序正确地使用此配置,并且不会出现任何错误?

EN

回答 1

Stack Overflow用户

发布于 2022-05-18 00:43:53

Serilog有一个SelfLog特性,允许您输出有关Serilog配置的诊断信息。您可以找到有关此功能这里的更多信息。

#tl;dr你可以输出这样的诊断信息。

Serilog.Debugging.SelfLog.Enable(msg => Debug.WriteLine(msg));

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72206375

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档