Search code examples
configurationversionsequenceserilog

Serilog : Unable to find a method called?


I have a ASP.NET Core 6 website with razor, this project are using serilog. The problem is that the SEQ logging do not work and I get the following in the output :

2022-11-28T10:59:07.0130000Z Unable to find a method called WithMachineName. Candidate methods are:
Serilog.LoggerConfiguration With(Serilog.Configuration.LoggerEnrichmentConfiguration, Serilog.Core.ILogEventEnricher)
Serilog.LoggerConfiguration AtLevel(Serilog.Configuration.LoggerEnrichmentConfiguration, System.Action`1[Serilog.Configuration.LoggerEnrichmentConfiguration], Serilog.Events.LogEventLevel, Serilog.Core.LoggingLevelSwitch)
Serilog.LoggerConfiguration FromLogContext(Serilog.Configuration.LoggerEnrichmentConfiguration)
2022-11-28T10:59:07.0180000Z Unable to find a method called WithProcessId. Candidate methods are:
Serilog.LoggerConfiguration With(Serilog.Configuration.LoggerEnrichmentConfiguration, Serilog.Core.ILogEventEnricher)
Serilog.LoggerConfiguration AtLevel(Serilog.Configuration.LoggerEnrichmentConfiguration, System.Action`1[Serilog.Configuration.LoggerEnrichmentConfiguration], Serilog.Events.LogEventLevel, Serilog.Core.LoggingLevelSwitch)
Serilog.LoggerConfiguration FromLogContext(Serilog.Configuration.LoggerEnrichmentConfiguration)
2022-11-28T10:59:07.0520000Z Unable to find a method called Console. Candidate methods are:
Serilog.LoggerConfiguration Sink(Serilog.Configuration.LoggerSinkConfiguration, Serilog.Core.ILogEventSink, Serilog.Events.LogEventLevel, Serilog.Core.LoggingLevelSwitch)
Serilog.LoggerConfiguration Logger(Serilog.Configuration.LoggerSinkConfiguration, System.Action`1[Serilog.LoggerConfiguration], Serilog.Events.LogEventLevel, Serilog.Core.LoggingLevelSwitch)
2022-11-28T10:59:07.0540000Z Unable to find a method called Seq. Candidate methods are:
Serilog.LoggerConfiguration Sink(Serilog.Configuration.LoggerSinkConfiguration, Serilog.Core.ILogEventSink, Serilog.Events.LogEventLevel, Serilog.Core.LoggingLevelSwitch)
Serilog.LoggerConfiguration Logger(Serilog.Configuration.LoggerSinkConfiguration, System.Action`1[Serilog.LoggerConfiguration], Serilog.Events.LogEventLevel, Serilog.Core.LoggingLevelSwitch)

The serilog implementation looks like this :

Appsettings.json

"serilog": {
    "Using": [],
    "MinimumLevel": {
      "Default": "Information",
      "Override": {
        "Microsoft": "Warning",
        "System": "Warning"
      }
    },
    "Enrich": [
      "FromLogContext",
      "WithMachineName",
      "WithProcessId"
    ],
    "WriteTo": [
      {
        "Name": "Console"
      },
      {
        "Name": "Seq",
        "Args": {
          "serverUrl": "https://192.168.1.4:5341/"
        }
      }
    ]
  }

The program.cs looks like this :

    var builder = WebAssemblyHostBuilder
                    .CreateDefault(args);
    var levelSwitch = new LoggingLevelSwitch();
    
                Serilog.Debugging.SelfLog.Enable(msg => Console.WriteLine(msg));
    
                Log.Logger = new LoggerConfiguration()
                    .MinimumLevel.ControlledBy(levelSwitch)
                    .Enrich.WithProperty("InstanceId", Guid.NewGuid().ToString("n"))
                    .ReadFrom.Configuration(builder.Configuration)
                    .WriteTo.BrowserConsole()
                    .CreateLogger();
    builder.Logging.AddProvider(new SerilogLoggerProvider());

I suspect that there is some mismatch with serilog versions between nugget packages, but I do not know how to really find out which package needs to be changed to what.

The project file got this Serilog nugget packages :

<PackageReference Include="Serilog.Enrichers.Environment" Version="2.2.0" />
    <PackageReference Include="Serilog.Enrichers.Process" Version="2.0.1" />
    <PackageReference Include="Serilog.Enrichers.Thread" Version="3.1.0" />
    <PackageReference Include="Serilog.Extensions.Hosting" Version="5.0.1" />
    <PackageReference Include="Serilog.Extensions.Logging" Version="3.1.0" />
    <PackageReference Include="Serilog.Settings.Configuration" Version="3.4.0" />
    <PackageReference Include="Serilog.Sinks.BrowserConsole" Version="1.0.0" />
    <PackageReference Include="Serilog.Sinks.Console" Version="4.1.0" />
    <PackageReference Include="Serilog.Sinks.Seq" Version="5.2.2" />

Solution

  • Using was missing in the appsettings.json file as well as some of the sinks was not supported in this platform.

    "serilog": {
        "Using": [
          "Serilog.Sinks.Seq",
          "Serilog.Enrichers.Environment"
        ]