3

I am trying to wire up my sinks and it seems for my rolling file sink my debug messages are not being logged (only info and above). Is my configuration wrong?

<!-- Serilog Configuration -->
<add key="serilog:using:Email" value="Serilog.Sinks.Email" />

<!-- Configure Serilog Email Sink -->
<add key="serilog:write-to:Email" />
<add key="serilog:write-to:Email.mailServer" value="***" />
<add key="serilog:write-to:Email.toEmail" value="***" />
<add key="serilog:write-to:Email.fromEmail" value="***" />
<add key="serilog:write-to:Email.mailSubject" value="Comply360 Portal Endpoint (DEV)" />
<add key="serilog:write-to:Email.restrictedToMinimumLevel" value="Warning" />
<add key="serilog:write-to:Email.outputTemplate" value="{Timestamp:HH:mm:ss} [{Level}] [{SourceContext}] [{CorrelationId}] {Message}{NewLine}{Exception}" />

<!-- Configure Serilog RollingFile Sink -->
<add key="serilog:write-to:RollingFile" />
<add key="serilog:write-to:RollingFile.restrictedToMinimumLevel" value="Debug" />
<add key="serilog:write-to:RollingFile.pathFormat" value="C:\Logs\comply360-portal-{Date}.txt" />
<add key="serilog:write-to:RollingFile.outputTemplate" value="{Timestamp:HH:mm:ss} [{Level}] [{SourceContext}] [{CorrelationId}] {Message}{NewLine}{Exception}" />
Marco
  • 2,453
  • 3
  • 25
  • 35

1 Answers1

6

There is nothing "wrong" with your RollingFile sink config per se - it will only log messages with log level Debug or above (i.e. it will not log Verbose messages) as you intended.

However, the minimum log level for Serilog in general is Information, so it doesn't even send to your sink.

You need to change Serilog's default minimum level to at least Debug, in your case:

<add key="serilog:minimum-level" value="Debug" />

Your final config should look like this:

<add key="serilog:minimum-level" value="Debug" />
<add key="serilog:write-to:RollingFile" />
<add key="serilog:write-to:RollingFile.restrictedToMinimumLevel" value="Debug" />
<add key="serilog:write-to:RollingFile.pathFormat" value="C:\Logs\log-portal-{Date}.txt" />
<add key="serilog:write-to:RollingFile.outputTemplate" value="{Timestamp:HH:mm:ss} [{Level}] [{SourceContext}] [{CorrelationId}] {Message}{NewLine}{Exception}" />

Of course, if you later decide to add any sink that logs Verbose messages and above, you'll need to change the minimum-level to Verbose too.

i.e. serilog:minimum-level should always be the lowest level from all of your sinks.

C. Augusto Proiete
  • 24,684
  • 2
  • 63
  • 91
  • really, you can't set the min level at the sink level? – Marco May 23 '16 at 11:56
  • and actually that is why i posted my code. it is not logging at the debug or higher level. it is logging at the info or higher (default) – Marco May 23 '16 at 11:58
  • i see what you are saying now. however, my rolling file did indeed still log messages but adding the global min level did the trick for all my sinks. – Marco May 23 '16 at 12:25
  • according to https://github.com/serilog/serilog/wiki/AppSettings and confirmed by my testing, you also need This is confirmed here: Solved for Github user dstj : https://github.com/serilog/serilog/issues/454#issuecomment-243561807 I edited the answer accordingly, and hope it will be approved. – pashute Nov 15 '16 at 23:14
  • “ serilog:minimum-level should always be the lowest level from all of your sinks.”. From https://github.com/serilog/serilog/wiki/AppSettings#adding-minimum-level-overrides: “ Since Serilog 2.1, minimum level overrides can be added to change the minimum level for some specific namespaces. This is done with the setting key serilog:minimum-level:override: followed by the source context prefix.” – Michael Freidgeim Nov 13 '21 at 21:58