Skip to content

Console application fails after upgrading to Serilog 7 #394

Closed
@SoftCircuits

Description

@SoftCircuits

My console application has been working fine. Recently, I made some changes and redeployed it, and now it's throwing an exception.

Unhandled exception. System.InvalidOperationException: No Serilog:Using configuration section is defined and no Serilog assemblies were found. This is most likely because the application is published as a single-file.

enter image description here

None of my changes were related to Serilog or logging. However, I did refresh all the NuGet packages with updates, including updating Serilog.AspNetCore from 6.1.0 to 7.0.0.

While it's true I have the Produce single file option checked, this options was working and I'd prefer to keep using it.

Does anyone know what might have changed in Serilog version 7 that could cause this?

Here's my configuration:

// Configure Serilog
string logFormat = "[{Timestamp:yyyy-MM-dd hh:mm:ss tt}][{Level:u3}] {Message:lj}{NewLine}{Exception}";
Log.Logger = new LoggerConfiguration()
    .ReadFrom.Configuration(appServices.Configuration)
    .WriteTo.Console(LogEventLevel.Verbose, logFormat)
    .WriteTo.File(LogFile, LogEventLevel.Verbose, logFormat)
    .WriteTo.List(LogEvents)
    .CreateLogger();

I'm using .NET 7.0. And here's my configuration section.

"Serilog": {
  "MinimumLevel": {
    "Default": "Information",
    "Override": {
      "Microsoft": "Warning",
      "System": "Warning"
    }
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions