Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Serilog - Configuring Multiple Sinks in AppSettings

Tags:

serilog

I am trying to wire-up serilog using the app settings package and when I run my program Serlog is complaining it cannot find the RollingFile assembly. I did not have this problem using a single sink but multiple it giving me fits:

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

<!-- 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="Notification" />
<add key="serilog:write-to:Email.restrictedToMinimumLevel" value="Debug" />

<!-- 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-user-mgmt-{Date}.txt" />
<add key="serilog:write-to:RollingFile.outputTemplate" value="{Timestamp:HH:mm:ss} [{Level}] [{SourceContext}] [{CorrelationId}] {Message}{NewLine}{Exception}" />
like image 771
Marco Avatar asked May 16 '16 17:05

Marco


2 Answers

You have to use prefix in web.config and in Configuration like this

Web.Config

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

<!-- Configure Serilog Email Sink -->
<add key="email:serilog:write-to:Email"/>
<add key="email:serilog:write-to:Email.mailServer" value="***" />
<add key="email:serilog:write-to:Email.toEmail" value="***" />
<add key="email:serilog:write-to:Email.fromEmail" value="***" />
<add key="email:serilog:write-to:Email.mailSubject" value="Notification" />
<add key="email:serilog:write-to:Email.restrictedToMinimumLevel" value="Debug" />

<!-- Configure Serilog RollingFile Sink -->
<add key="file:serilog:write-to:RollingFile" />
<add key="file:serilog:write-to:RollingFile.restrictedToMinimumLevel" value="Debug" />
<add key="file:serilog:write-to:RollingFile.pathFormat" value="C:\Logs\comply360-user-mgmt-{Date}.txt" />
<add key="file:serilog:write-to:RollingFile.outputTemplate" value="{Timestamp:HH:mm:ss} [{Level}] [{SourceContext}] [{CorrelationId}] {Message}{NewLine}{Exception}" />

Startup.cs

 Log.Logger = new LoggerConfiguration()
            .ReadFrom
            .AppSettings("email")
            .ReadFrom
            .AppSettings("file")
            .CreateLogger()
like image 195
Spharah Avatar answered Oct 03 '22 22:10

Spharah


figured it out. i had to remove the rolling file using statement.

like image 42
Marco Avatar answered Oct 03 '22 23:10

Marco