I'm actually trying to troubleshoot a problem where the MSSqlServer sink isn't writing anything to my database tables. I was advised to hook up the SelfLog to see what was going on but it isn't actually outputting anything and I'm not sure if I'm missing something. This is the setup method:
public SerilogLogger()
{
Serilog.Debugging.SelfLog.Enable(
msg => System.Diagnostics.Trace.WriteLine(msg));
_logger = new LoggerConfiguration()
.WriteTo.MSSqlServer(@"Server=<MyConnectionString>", "Logs")
.WriteTo.Trace()
.CreateLogger();
}
The methods in this class are just calling log methods on the _logger
which is set up here. The logs that I'm creating are being written to the output window via the trace sink, but nothing goes to the database and Serilog isn't outputting anything let alone any errors. I even tried deliberately messing up the connection string just to get it to output anything and no dice. Any thoughts?
I know this is a pretty old question but I spent a couple of days dealing with a similar issue, so I will just leave some suggestions here.
IF you are using the global Log
object, make sure you are actually sending stuff. Serilog queues requests and sends them all once you execute:
Log.CloseAndFlush();
Without this, nothing will be logged. Make sure to execute this at the very end as after this, the logger will be closed (Serilog's Lifecycle documentation).
If you're not using the global object, this should be executed once your logging object is disposed.
Try to see if Serilog is actually showing errors by forcing one. Just delete one character in your connection string or something like that to see if Serilog's exception appears in the console.
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