Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Method not found: 'Serilog.LoggerConfiguration

Tags:

c#

serilog

I have a main logger for my solution which is defined as

    Log.Logger = new LoggerConfiguration()
        .MinimumLevel.Verbose()
        .WriteTo.LiterateConsole(LogEventLevel.Verbose)
        .WriteTo.RollingFile($"{appLogDir}{Path.DirectorySeparatorChar}logs{Path.DirectorySeparatorChar}V-RPi-{{Date}}.log")
        .WriteTo.RollingFile($"{appLogDir}{Path.DirectorySeparatorChar}logs-warnings{Path.DirectorySeparatorChar}V-RPi-{{Date}}.log", LogEventLevel.Warning)
        .WriteTo.File($"{appLogDir}{Path.DirectorySeparatorChar}recent-log.log", fileSizeLimitBytes: 134217728, restrictedToMinimumLevel: LogEventLevel.Verbose)
        .CreateLogger();

I want to create two separate loggers to log things in two class instances. I have defined them as below. This is located in a separate assembly from the main project.

private ILogger comRespLog;
public **constructor**(string name)
{
comRespLog = new LoggerConfiguration()
                .MinimumLevel.Verbose()            
                .WriteTo.RollingFile($"{appLogDir}{Path.DirectorySeparatorChar}logs-CommandResponse-{Name}{Path.DirectorySeparatorChar}V-RPi-{{Date}}.log")
                .CreateLogger();
}

I receive no build errors but I receive this at run time.

Method not found: 'Serilog.LoggerConfiguration Serilog.RollingFileLoggerConfigurationExtensions.RollingFile(Serilog.Configuration.LoggerSinkConfiguration, System.String, Serilog.Events.LogEventLevel, System.String, System.IFormatProvider, System.Nullable1<Int64>, System.Nullable1, Serilog.Core.LoggingLevelSwitch, Boolean, Boolean, System.Nullable`1)'."}

like image 553
TheColonel26 Avatar asked Dec 16 '16 15:12

TheColonel26


People also ask

Can you stop logging with Serilog?

For example, if you are using Serilog you should configure Log. Logger and LibLog will use it. Also you can disable logging by setting LogProvider. IsDisabled to true . "

What is Minimumlevel in Serilog?

Serilog defines several levels of log events. From low to high, these are Verbose , Debug , Information , Warning , Error and Fatal . You can set the minimum level you want to log, meaning that events for that level or higher will be logged.

What is Serilog sink?

Serilog is a newer logging framework for . NET. It was built with structured logging in mind. It makes it easy to record custom object properties and even output your logs to JSON. Note: You can actually check out our other tutorials for NLog and log4net to learn how to do structured logging with them also!

What is enrich in Serilog?

Log Context enricher - Built in to Serilog, this enricher ensures any properties added to the Log Context are pushed into log events. Environment enrichers - Enrich logs with the machine or current user name.


1 Answers

Turns out I was referencing an older nuget package in my Main Assembly than I was in the sub assembly. After updating them so they match the problem went away.

like image 66
TheColonel26 Avatar answered Sep 20 '22 14:09

TheColonel26