TheColonel26
TheColonel26

Reputation: 2728

Method not found: 'Serilog.LoggerConfiguration

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

Upvotes: 9

Views: 21262

Answers (5)

Scooter
Scooter

Reputation: 374

enter image description here

In my case, I had the QBO SDK, with Serilog libraries in tow, installed in 2 projects within my solution. Project _Presention only needed the QBO SDK to support QBO data types for use in presenting data in grids and I was not using the Serilog libraries for anything else in _Presentation.

Project Services was the project that was actually communicating with QBO Online via the API, thus needing the Serilog libraries.

I removed the Serilog references in the app.config file for Project _Presentation. At which point, the error no longer was present and I was able to communicate with QBL Online.

Upvotes: 0

rishan mehmi
rishan mehmi

Reputation: 1

For me, the workaround was removing references from web.config, as the versions were fixed and still i was facing issues, so I removed the assembly references from the web.config, and thanks to .net compiler, it targets, as I can think, if a reference is there, to the target interface and hence cannot find things exactly implemented, remove references from web.config of the dll, and the IIS will automatically pick up references from the class file.

Upvotes: 0

Jhonny Ramirez Zeballos
Jhonny Ramirez Zeballos

Reputation: 3196

Should install the serilog for the netcore framework.

dotnet add package Serilog.AspNetCore --version 4.1.0

Upvotes: 0

Sameer Bahad
Sameer Bahad

Reputation: 583

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/..)

Upvotes: 4

TheColonel26
TheColonel26

Reputation: 2728

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.

Upvotes: 16

Related Questions