Shezad Ahmed
Shezad Ahmed

Reputation: 69

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

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" />

Upvotes: 4

Views: 16288

Answers (4)

Patrick Byers
Patrick Byers

Reputation: 43

I received a similar error on File, not Debug: 'LoggerSinkConfiguration' does not contain a definition for 'File' and no accessible extension method 'File' accepting a first argument of type 'LoggerSinkConfiguration' could be found (are you missing a using directive or an assembly reference?).

The error was in a code block like this:

Log.Logger = new LoggerConfiguration()
    .MinimumLevel.ControlledBy(LevelSwitch)
    .WriteTo.File(logFilePath, shared: true, outputTemplate: "...")
    .CreateLogger();

I was missing dependency references to and installed packages Serilog.Exceptions and Serilog.Sinks.File.

Installing them in Visual Studio through "Manage Nuget packeges..." fixed this issue for me. I only had Serilog itself beforehand.

This other issue on Github and the comment here from AHeraldOfTheNewAge made me think about how I might need "further dependency(s)" and that the answer was to "simply install" the packages I needed.

(We were migrating from paket to nuget, so lucky for me the packages I needed were listed in the old paket.dependencies file!)

Upvotes: 0

Chuck Smith
Chuck Smith

Reputation: 104

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.

Upvotes: 8

AHeraldOfTheNewAge
AHeraldOfTheNewAge

Reputation: 57

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

Upvotes: 0

Nicholas Blumhardt
Nicholas Blumhardt

Reputation: 31877

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" />

Upvotes: 1

Related Questions