question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

System.TypeLoadException: Method 'Verbose' in type 'Serilog.Extensions.Hosting.ReloadableLogger' from assembly 'Serilog.Extensions.Hosting'

See original GitHub issue

Installed 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:closed
  • Created 2 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
skomis-mmcommented, Nov 21, 2021

Ok, just change the line

dotnet publish -c Release -o out

to

 dotnet publish web -c Release -o out

I read somewhere that publish on .sln is not a recommended way because can have unpredicted results. (Lib published artifacts overwrites Web artifacts). At least, in current tooling (check dotnet/sdk) . Instead, do your publish just for the end project (Web.csproj)

1reaction
klysecommented, Nov 19, 2021

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:

Web/appsettings.[Dd]evelopment.json
*.env
.envrc
.git
.dockerignore
.gitignore
.vs
.vscode
docker-compose.yml
docker-compose.*.yml
*/bin
*/obj
Read more comments on GitHub >

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

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found