System.TypeLoadException: Method 'Verbose' in type 'Serilog.Extensions.Hosting.ReloadableLogger' from assembly 'Serilog.Extensions.Hosting'
See original GitHub issueInstalled nuget packages
<PackageReference Include="AspNetCore.HealthChecks.NpgSql" Version="5.0.2" />
<PackageReference Include="FluentValidation.AspNetCore" Version="10.3.4" />
<PackageReference Include="MediatR.Extensions.Microsoft.DependencyInjection" Version="9.0.0" />
<PackageReference Include="Sentry.AspNetCore" Version="3.10.0" />
<PackageReference Include="Sentry.Serilog" Version="3.9.3" />
<PackageReference Include="Serilog" Version="2.10.0" />
<PackageReference Include="Serilog.AspNetCore" Version="4.1.0" />
<PackageReference Include="Serilog.Extensions.Hosting" Version="4.2.0" />
<PackageReference Include="Serilog.Extensions.Logging" Version="3.1.0" />
<PackageReference Include="Serilog.Formatting.Compact" Version="1.1.0" />
<PackageReference Include="Serilog.Settings.Configuration" Version="3.3.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="4.0.0" />
<PackageReference Include="Serilog.Sinks.Debug" Version="2.0.0" />
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
<PackageReference Include="Serilog.Sinks.Fluentd" Version="0.4.0" />
<PackageReference Include="Serilog.Sinks.PeriodicBatching" Version="2.3.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
Also tried with a more minimalistic set of nugets:
<PackageReference Include="AspNetCore.HealthChecks.NpgSql" Version="5.0.2" />
<PackageReference Include="FluentValidation.AspNetCore" Version="10.3.4" />
<PackageReference Include="MediatR.Extensions.Microsoft.DependencyInjection" Version="9.0.0" />
<PackageReference Include="Sentry.AspNetCore" Version="3.10.0" />
<PackageReference Include="Sentry.Serilog" Version="3.10.0" />
<PackageReference Include="Serilog.AspNetCore" Version="4.1.0" />
<PackageReference Include="Serilog.Sinks.Fluentd" Version="0.4.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
OS
Docker
mcr.microsoft.com/dotnet/aspnet:5.0
Additional Information
ASP.Net Core 5.0 app running in a docker container
Code
private static LoggerConfiguration ConfigureLogger(LoggerConfiguration loggerConfig)
{
loggerConfig
.MinimumLevel.Override("Microsoft", LogEventLevel.Warning)
.MinimumLevel.Override("Microsoft.EntityFrameworkCore", LogEventLevel.Warning)
.MinimumLevel.Override("Microsoft.AspNetCore.SignalR", HostingEnvHelper.IsDevelopment ? LogEventLevel.Debug : LogEventLevel.Warning)
.MinimumLevel.Override("Microsoft.AspNetCore.Http.Connections", HostingEnvHelper.IsDevelopment ? LogEventLevel.Debug : LogEventLevel.Warning)
.Enrich.FromLogContext()
.WriteTo.Sentry()
.WriteTo.Console();
return loggerConfig;
}
public static int Main(string[] args)
{
// Serilog.Debugging.SelfLog.Enable(Console.WriteLine);
Log.Logger = ConfigureLogger(new LoggerConfiguration())
.MinimumLevel.Debug()
.CreateBootstrapLogger();
....
}
....
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder
.UseStartup<Startup>()
.UseSentry()
.UseUrls("http://+:5003");
})
.UseSerilog((context, _, configuration) =>
ConfigureLogger(configuration)
.ReadFrom.Configuration(context.Configuration));
Exception
root@f342f6bbdb2a:/app# dotnet Web.dll
Unhandled exception. System.TypeLoadException: Method 'Verbose' in type 'Serilog.Extensions.Hosting.ReloadableLogger' from assembly 'Serilog.Extensions.Hosting, Version=2.0.0.0, Culture=neutral, PublicKeyToke
n=24c2f752a8e58a10' does not have an implementation.
Aborted
Steps tried to resolve the issue
- Install different versions of the serilog nuget packages
- Removed all config from
appsettings.*.json
- Different container versions:
mcr.microsoft.com/dotnet/aspnet:5.0.12
,mcr.microsoft.com/dotnet/aspnet:5.0.5
and some more - Multiple docker builds with
--no-cache
Hint to where the problem comes from
When changing .CreateBootstrapLogger()
to CreateLogger()
and adjusting CreateHostBuilder
of course the issue is gone.
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Unable to resolve service for'Serilog.Extensions.Hosting. ...
I get the following exception when I want to use Custom SerilogRequestLogging as a middleware: System.InvalidOperationException: Unable to ...
Read more >Adding Serilog to the ASP.NET Core Generic Host
In this post I introduce the Serilog.Extensions.Hosting package for ASP.NET Core generic hosts, discuss why it's necessary, and describe how ...
Read more >Serilog.Extensions.Logging 7.0.0
The package implements AddSerilog() on ILoggingBuilder and ILoggerFactory to enable the Serilog provider under the default Microsoft.Extensions.Logging ...
Read more >Serilog.Extensions.Hosting 7.0.0
Serilog support for .NET Core logging in hosted services.
Read more >Bootstrap logging with Serilog + ASP.NET Core
Logger is a ReloadableLogger , it will be reconfigured through the callback, and then “frozen” into the efficient, immutable logging pipeline ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Ok, just change the line
to
I read somewhere that
publish
on.sln
is not a recommended way because can have unpredicted results. (Lib
published artifacts overwritesWeb
artifacts). At least, in current tooling (checkdotnet/sdk
) . Instead, do your publish just for the end project (Web.csproj
)EDIT: having a detailed
.dockerignore
makes absolutely sense, but did not solve my issue. The test I made was on a wrong branch.Found the solution myself. The.dockerignore
did not exclude build results and therefore copied the binaries into the container which led to this issue.Here is the
.dockerignore
that worked for us: