Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Serilog SelfLog not outputting anything

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?

like image 992
Sinaesthetic Avatar asked Sep 20 '16 22:09

Sinaesthetic


1 Answers

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.

  1. 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.

  2. 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.

like image 84
JDC Avatar answered Nov 14 '22 18:11

JDC