2

I'm trying to use Serilog with the Raygun sink using AutoFac

I successfully configure Serilog with AutoFact using https://groups.google.com/forum/#!topic/serilog/R23B8CLso9Q

If I want to log a trace/debug/info to a log rolling file ONLY and warning/error/fatal to a rolling file and raygun

How can I configure the log?

This is my actual conf:

public static ILogger CreateLogger()
        {
            var config = new LoggerConfiguration()
                            .ReadAppSettings();

            InitialiseGlobalContext(config);

            return config.CreateLogger();
        }

with the this web.config entries:

<add key="serilog:minimum-level" value="Verbose" />
<add key="serilog:write-to:RollingFile.path" value="D:\WebRole\Logs\file-{Date}.txt" />
<add key="serilog:write-to:RollingFile.fileSizeLimitBytes" value="1024" />
<add key="serilog:write-to:RollingFile.retainedFileCountLimit" value="10" />
<add key="serilog:write-to:RollingFile.outputTemplate" value="{Timestamp} [{Level}] [{MachineName},{ApplicationName},{RuntimeVersion}] {Message}{NewLine}{Exception}" />

Since the conf is global, if I add .WriteTo.Raygun(), It will log trace/debug/info to raygun I dont want that.

Any ideas

2 Answers2

0

You should be able to add an additional config entry to limit events via the Raygun sink:

<add key="serilog:write-to:Raygun.restrictedToMinimumLevel" value="Warning" />

You will also need to ensure the Raygun assembly is in the project's build output directory, and referenced with a "using" entry like:

<add key="serilog:using" value="Serilog.Sinks.Raygun" />
Nicholas Blumhardt
  • 30,271
  • 4
  • 90
  • 101
  • I added the following entries `` ``, It does not log anything to Raygun. I'm using the following pkgs versions `"Mindscape.Raygun4Net.Signed" version="4.2.1" "Serilog" version="1.4.168" "Serilog.Extras.AppSettings" version="1.4.168" "Serilog.Extras.Web" version="1.4.168" "Serilog.Sinks.Raygun" version="1.4.168"` do I need Mindscape.Raygun4Net.Mvc as it is a MVC site? what I'm missing here – Julian Bueno Feb 13 '15 at 04:13
  • You probably need `serilog:using` as described here: https://github.com/serilog/serilog/wiki/AppSettings#using-sink-extensions-from-additional-assemblies - edited answer. – Nicholas Blumhardt Feb 15 '15 at 22:22
0

For anyone coming to this (like me) the answer is how @NicholasBlumhardt described. I however also made a mistake of not having the applicationKey immediately after the using

<add key="serilog:using:Raygun" value="Serilog.Sinks.Raygun" />
<add key="serilog:write-to:Raygun.applicationKey" value="MYRAYGUNAPPLICATIONKEY" />
<add key="serilog:write-to:Raygun.restrictedToMinimumLevel" value="Information" />
Roffers
  • 691
  • 1
  • 8
  • 16