Reputation: 15991
I did some consolidation of my NuGet packages across my solution and now I'm receiving:
exception message:
MissingMethodException: Method not found: 'System.IDisposable Serilog.Context.LogContext.Push(Serilog.Core.ILogEventEnricher)'.
call stack on the exception:
at Serilog.Extensions.Logging.SerilogLoggerProvider.BeginScope[T](T state) at Microsoft.Extensions.Logging.Logger.BeginScope[TState](TState state)
when I make a call like this:
using (logger.BeginScope(new Dictionary<string, object>
{
["SomeProperty"] = someVariable,
}))
{
logger.LogInfo("hello world");
}
package.config
<package id="Microsoft.Extensions.Logging" version="2.1.1" targetFramework="net48" />
<package id="Serilog" version="2.10.0" targetFramework="net48" />
<package id="Serilog.Extensions.Logging" version="3.0.1" targetFramework="net48" />
It would seem I have an incorrect NuGet reference but I'm not seeing it.
I also put together a full repro of the problem here.
Upvotes: 1
Views: 734
Reputation: 27818
As you already know, the issue is with the package Serilog.Enrichers.ClientInfo including an old version of Serilog.dll
within the NuGet package, which is wrong (as it's supposed to be a dependency via NuGet only), thus the long-term fix is the maintainer fix that as you reported.
A short-term fix, would be to manually edit your .csproj
file to use the correct Serilog.dll
, from the Serilog package:
<Reference Include="Serilog, Version=2.0.0.0, Culture=neutral, PublicKeyToken=24c2f752a8e58a10, processorArchitecture=MSIL">
<HintPath>..\packages\Serilog.2.10.0\lib\net46\Serilog.dll</HintPath>
</Reference>
Your repro project is pointing to the Serilog.dll
that is inside of the Serilog.Enrichers.ClientInfo package:
<Reference Include="Serilog, Version=2.0.0.0, Culture=neutral, PublicKeyToken=24c2f752a8e58a10, processorArchitecture=MSIL">
<HintPath>..\packages\Serilog.Enrichers.ClientInfo.1.1.2\lib\net452\Serilog.dll</HintPath>
</Reference>
You can also add a post-build step that always copies the correct Serilog.dll
to the output folder of your project.
Update: This has been fixed in Serilog.Enrichers.ClientInfo v1.1.3.
Upvotes: 2
Reputation: 15991
Serilog.Enrichers.ClientInfo is including Serilog v2.4.0.0
, an old version, with their NuGet package:
I've opened an issue on the GitHub project.
Upvotes: 0