8

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)'."}

TheColonel26
  • 2,618
  • 7
  • 25
  • 50

3 Answers3

15

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.

TheColonel26
  • 2,618
  • 7
  • 25
  • 50
  • Hi @theColonel26 I am facing a similar issue, https://stackoverflow.com/questions/58086137/method-not-found-serilog-loggerconfiguration-serilog-loggerconfigurationlogent . Could you please help me in fixing it. – Madhur Maurya Sep 24 '19 at 18:41
  • For reference, my fix was just to upgrade all Serilog references in nuget to latest version and error went away. So that was a relatively quick way to fix :) – weeksdev Jun 29 '21 at 14:34
3

Issue due to version mismatch

Your code is correct just match version

I was using Version 2.0 instead of 1.5

Please match your version with (if you are using Active Directory / Azure Active Directory)

Steps

  1. UnInstall Serilog

  2. Install Serilog with match version (1.5/ 2.0/..)

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Sameer Bahad
  • 555
  • 5
  • 4
0

Should install the serilog for the netcore framework.

dotnet add package Serilog.AspNetCore --version 4.1.0