Serilog ms sql sink 不写入我的表 [英] Serilog ms sql sink not writing to my table

查看:50
本文介绍了Serilog ms sql sink 不写入我的表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Log.Information("Hello"); 没有写入表格.我在自述文件中使用了基本配置 here 并且接收器创建了我的表 OK第一次运行.我确定我的用户具有读/写权限.

The Log.Information("Hello"); is not writing to the table. I have used the basic configuration here in the readme file and the sink created my table OK on first run. I am certain that my user has read/write permission.

我期待 Log.Information("Hello"); 向表中添加一行.

I am expecting the Log.Information("Hello"); to add a row to the table.

Serilog.Debugging.SelfLog.Enable(msg => Debug.WriteLine(msg));
var logDB = @"data source=xxxxxx\SQLEXPRESS;initial catalog=Eng;integrated security=False;persist security info=True;user id=xxxx;password=xxxxxxxx";
 var sinkOpts = new SinkOptions();
 sinkOpts.TableName = "SL24AddInLogging";
 sinkOpts.AutoCreateSqlTable = true;
 var columnOpts = new ColumnOptions();
 columnOpts.Store.Remove(StandardColumn.Properties);
 columnOpts.Store.Add(StandardColumn.LogEvent);
 columnOpts.LogEvent.DataLength = 2048;
 columnOpts.PrimaryKey = columnOpts.TimeStamp;
 columnOpts.TimeStamp.NonClusteredIndex = true;

 var log = new LoggerConfiguration()
     .WriteTo.MSSqlServer(
      connectionString: logDB,
      sinkOptions: sinkOpts,
      columnOptions: columnOpts
 ).CreateLogger();

我一定是做错了什么.什么?

I must be doing something wrong. What?

推荐答案

我发现了我的问题.过去,当我使用 Serilog 时,我使用了静态Log.Information()",而不是在创建记录器时在代码中声明的变量.在这种情况下,我声明的变量也是log" - 小写.

I found my issue. In the past when I have used Serilog I have used the static "Log.Information()" rather than my variable that is declared in my code when I create the logger. In this case my declared variable is also "log" - lower case.

Log.Information() - 不好.

Log.Information() - bad.

log.Information() - 很好.

log.Information() - good.

编辑此外,万一你遇到这种情况.我使用静态版本在整个项目中都可以使用我的日志记录.要定义记录器并使其可用,您可以使用以下模式:

Edit In addition, in case you run into this. I have used the static version to have my logging available throughout the entire project. To define a logger and have it available you can use the following pattern:

var log = new LoggerConfiguration()
 .WriteTo.MSSqlServer(
  connectionString: logDB,
  sinkOptions: sinkOpts,
  columnOptions: columnOpts
      ).CreateLogger();

Log.Logger = log;

这篇关于Serilog ms sql sink 不写入我的表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆