Serilog MSSqlServer 接收器不写入表 [英] Serilog MSSqlServer sink not writing to table
问题描述
我的 Startup.cs 中有以下语句:
I have the following statement in my Startup.cs:
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Debug()
.WriteTo.ColoredConsole()
.WriteTo.MSSqlServer("Server=(localdb)\\MSSQLLocalDB;Database=myDb.Logging;Trusted_Connection=True;", "Logs", autoCreateSqlTable: true)
.WriteTo.RollingFile(pathFormat: Path.Combine(logPath, "Log-{Date}.txt"))
.CreateLogger();
在我的配置方法中:
loggerFactory.AddSerilog();
当我启动应用程序时,表被创建,所以我知道连接有效.我将输出记录到控制台和文件,但是,没有输出到数据库表.
When I start the application, the table is created so I know the connection works. I get logged output to the console and to the file, however, no output to the database table.
我做错了什么?
其他信息:使用asp.net core rc2-final,针对net461,使用Serilog.Sinks.MSSqlServer 4.0.0-beta-100
Other information: using asp.net core rc2-final, targeting net461, and using Serilog.Sinks.MSSqlServer 4.0.0-beta-100
推荐答案
乍一看,您似乎没有遗漏任何东西.很可能是 SQL Server Sink 在尝试写入表时抛出异常.
At first glance it doesn't look like you're missing anything. It's likely that an exception is being thrown by the SQL Server Sink when trying to write to the table.
您是否尝试检查 Serilog 的自我日志 的输出?
Have you tried checking the output from Serilog's self log?
Serilog.Debugging.SelfLog.Enable(msg => Console.WriteLine(msg));
<小时>
更新:看起来您的 SQL Server/本地数据库存在权限问题.此错误消息表明接收器正在尝试运行 ALTER TABLE 语句,而运行该应用程序的用户无权执行 ALTER TABLE 语句.
Update: Looks like a permission issue with you SQL Server/Local DB. This error message suggests the sink is trying to run an ALTER TABLE statement and the user running the application doesn't have permission to execute an ALTER TABLE statement.
更新 2:我建议你使用完整的 .NET + Serilog v1.5.14 + Serilog.Sinks.MSSqlServer v3.0.98 编写一个简单的控制台应用程序,看看你是否得到相同的行为......只是为了排除可能性.NET Core 实现或您使用的 Beta sink 版本存在问题
Update 2: I suggest you write a simple Console App using the full .NET + Serilog v1.5.14 + Serilog.Sinks.MSSqlServer v3.0.98 to see if you get the same behavior... Just to rule out the possibility that there's a problem with the .NET Core implementation or with the beta sink version you're using
这篇关于Serilog MSSqlServer 接收器不写入表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!