Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Console application fails after upgrading to Serilog 7 #394

Closed
SoftCircuits opened this issue Aug 21, 2023 · 9 comments
Closed

Console application fails after upgrading to Serilog 7 #394

SoftCircuits opened this issue Aug 21, 2023 · 9 comments

Comments

@SoftCircuits
Copy link

SoftCircuits commented Aug 21, 2023

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"
    }
  }
}
@0xced
Copy link
Member

0xced commented Aug 21, 2023

Thank you for the bug report. This issue has already been brought to our attention in #389. It is already fixed by #391 which is merged in the dev branch but a new NuGet package has not yet been released.

In the meantime, the recommended workaround is to specify one assembly through the ConfigurationReaderOptions object.

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

@0xced 0xced closed this as completed Aug 21, 2023
@SoftCircuits
Copy link
Author

SoftCircuits commented Aug 21, 2023

@0xced Thanks for the timely response. I will review your workaround and keep an eye out for the next update. I found my project also runs if I just don't produce a single file.

@nblumhardt
Copy link
Member

@0xced I've queued up #395 - think this is ready to merge/release?

@0xced
Copy link
Member

0xced commented Aug 22, 2023

Yes, releasing 7.0.1 with these two bug fixes is a good idea in my opinion.

@0xced
Copy link
Member

0xced commented Aug 24, 2023

Serilog.Settings.Configuration 7.0.1, which fixes this issue, is now released on NuGet, enjoy! 🚀

@SoftCircuits
Copy link
Author

@0xced Sorry, but I had another question about this.

Actually, I had not installed Serilog.Settings.Configuration. I thought you were updating the main component. Would installing this package still fix this issue for me?

@0xced
Copy link
Member

0xced commented Aug 29, 2023

Serilog.Settings.Configuration is a dependency of the Serilog.AspNetCore package, as you can see on its NuGet page: Serilog.Settings.Configuration (>= 7.0.0) It means that even though you have not explicitly installed this package, it is already (implicitly) installed as a dependency.

So yes, installing version 7.0.1 explicitly of Serilog.Settings.Configuration will solve your issue.

@SoftCircuits
Copy link
Author

SoftCircuits commented Aug 29, 2023

@0xced Cool. Thanks again. I guess the NuGet manager in Visual Studio isn't smart enough to see I have that dependency.

@0xced
Copy link
Member

0xced commented Aug 29, 2023

I haven't used Visual Studio in years so I can't tell. But JetBrains Rider helps understanding implicitly installed packages, see screenshot. 😉

Serilog Settings Configuration implicit dependency

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants