简体   繁体   English

MissingMethodException Serilog.Context.LogContext.Push

[英]MissingMethodException Serilog.Context.LogContext.Push

I did some consolidation of my NuGet packages across my solution and now I'm receiving:我在我的解决方案中对我的 NuGet 包进行了一些整合,现在我收到了:

exception message:异常消息:

MissingMethodException: Method not found: 'System.IDisposable Serilog.Context.LogContext.Push(Serilog.Core.ILogEventEnricher)'. MissingMethodException:找不到方法:'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)在 Serilog.Extensions.Logging.SerilogLoggerProvider.BeginScope[T](T 状态) 在 Microsoft.Extensions.Logging.Logger.BeginScope[TState](TState 状态)

when I make a call like this:当我这样打电话时:

using (logger.BeginScope(new Dictionary<string, object>
{
    ["SomeProperty"] = someVariable,
}))
{
    logger.LogInfo("hello world");
}

package.config 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.看来我有一个不正确的 NuGet 参考,但我没有看到它。

I also put together a full repro of the problem here .我还在这里对问题进行了完整的复制

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 . 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 是您报告的维护者修复。

A short-term fix, would be to manually edit your .csproj file to use the correct Serilog.dll , from the Serilog package:短期修复是手动编辑您的.csproj文件以使用来自 Serilog package 的正确Serilog.dll

<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:您的复制项目指向Serilog.dll内部的Serilog.dll

<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.您还可以添加一个构建后步骤,该步骤始终将正确的Serilog.dll复制到项目的 output 文件夹中。


Update : This has been fixed in Serilog.Enrichers.ClientInfo v1.1.3 .更新:这已在Serilog.Enrichers.ClientInfo v1.1.3中修复。

Serilog.Enrichers.ClientInfo is including Serilog v2.4.0.0 , an old version, with their NuGet package:Serilog.Enrichers.ClientInfo包括旧版本Serilog v2.4.0.0 v2.4.0.0 及其 NuGet package:

nuget 包中包含的 serilog dll 的屏幕截图

I've opened an issue on the GitHub project.我在 GitHub 项目上打开了一个问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM