'LoggerSinkConfiguration' does not contain a definition for 'Debug'

Viewed 4821

I have taken over a project which uses SeriLog.

When I try and build the project I get Error CS1061 'LoggerSinkConfiguration' does not contain a definition for 'Debug' and no accessible extension method 'Debug' accepting a first argument of type 'LoggerSinkConfiguration' could be found (are you missing a using directive or an assembly reference?)

It fails on

    internal static LoggerConfiguration AddDebugSink(this LoggerConfiguration loggerConfig)
    {
        
        return loggerConfig.WriteTo.Debug();
    }

Here are my references

<PackageReference Include="Serilog" Version="2.10.0" />
<PackageReference Include="Serilog.Enrichers.Environment" Version="2.1.3" />
<PackageReference Include="Serilog.Enrichers.Thread" Version="3.1.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="3.1.1" />
<PackageReference Include="Serilog.Sinks.Debug" Version="1.0.1" />
<PackageReference Include="Serilog.Sinks.File" Version="4.1.0" />
<PackageReference Include="Serilog.Sinks.MSSqlServer" Version="5.6.0" />
3 Answers

Try switching to version 2.0.0 of the Serilog.Sinks.Debug package - version 1.0.1, which you're using, has type names that conflict with the console sink.

<PackageReference Include="Serilog.Sinks.Debug" Version="2.0.0" />

I had a similar problem with serilog debug, the fix for me was simply installig the serilog debug package from nuget package manager, hope this helps someone..

I received Error CS1061 does not contain a definition for configuration on this block of code in the constructor of an AWS Lambda function:

_configuration = new ConfigurationBuilder()
.AddJsonFile("loggerSettings.json", true)
.Build();
Log.Logger = new LoggerConfiguration()
.ReadFrom.Configuration(_configuration)  //ERROR WAS HERE
.Enrich.FromLogContext()
.Enrich.WithMachineName()
.Enrich.WithDemystifiedStackTraces()
.CreateLogger();

By installing the package Serilog.Settings.Configuration the error went away.

Related