Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Serilog Configurable SQL Server Sink

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

like image 899
aghost Avatar asked Dec 11 '25 23:12

aghost


1 Answers

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"/>
like image 187
Nicholas Blumhardt Avatar answered Dec 13 '25 17:12

Nicholas Blumhardt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!