I'm trying to set up a Serilog logger with a SQL Server Sink that is configurable in the web.config.
Is there a way to do this in a manner like, for example, with the rolling file sink?
Example:
<add key="serilog:write-to:RollingFile.pathFormat" value="C:\Logs\Log_File_{Date}.txt" />
I have downloaded the MSSQL extension for serilog and it works in code like (C#):
public ILogger Log = new LoggerConfiguration().WriteTo.MSSqlServer(@"Server=.;Database=LogDatabase;Trusted_Connection=True;", "Logs").ReadFrom.AppSettings().CreateLogger();
But not like:
<add key="serilog:write-to:MSSqlServer" value="Server=.;Database=LogDatabase;Initial Catalog=Logs;Trusted_Connection=True;"/>
Sure there are possibilities to work around this but I'm still wondering if it's possible, for curiosity and better looking code.
Has anyone out there got it to work?
Thankful for replies
It's possible you're missing:
<add key="serilog:using:MSSqlSever" value="Serilog.Sinks.MSSqlServer" />
You also need to name the connectionString argument, and you'll need tableName also:
<add key="serilog:write-to:MSSqlServer.connectionString" value="Server=.;Database=..."/>
<add key="serilog:write-to:MSSqlServer.tableName" value="Logs"/>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With