c# - MissingMethodException Serilog.Context.LogContext.Push
问题描述
我在我的解决方案中对我的 NuGet 包进行了一些整合,现在我收到了:
异常消息:
MissingMethodException:找不到方法:'System.IDisposable Serilog.Context.LogContext.Push(Serilog.Core.ILogEventEnricher)'。
异常调用堆栈:
在 Serilog.Extensions.Logging.SerilogLoggerProvider.BeginScope[T](T state) 在 Microsoft.Extensions.Logging.Logger.BeginScope[TState](TState state)
当我这样打电话时:
using (logger.BeginScope(new Dictionary<string, object>
{
["SomeProperty"] = someVariable,
}))
{
logger.LogInfo("hello world");
}
包配置
<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" />
我似乎有一个不正确的 NuGet 引用,但我没有看到它。
我还在这里对问题进行了完整的复制。
解决方案
如您所知,问题在于包Serilog.Enrichers.ClientInfo包括Serilog.dll
NuGet 包中的旧版本,这是错误的(因为它应该是仅通过 NuGet 的依赖项),因此长期修复是正如您报告的那样,维护者修复了该问题。
一个短期的解决方法是从 Serilog 包中手动编辑您的.csproj
文件以使用正确的 .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>
您的 repro项目指向Serilog.Enrichers.ClientInfo包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>
您还可以添加一个构建后步骤,该步骤始终将正确的内容复制Serilog.dll
到项目的输出文件夹中。
更新:这已在Serilog.Enrichers.ClientInfo v1.1.3中修复。
推荐阅读
- firebase - 不明白为什么我在使用 image_picker 时会出现这个错误
- javascript - React 本机项目不运行 iOS
- javascript - Linux electron npm 给我 install-app-deps:未找到
- android - 未生成 Firebase 消息传递令牌
- reactjs - 如何将 handleTheme() 函数发送到路由?
- android - 如何在 Android 中使用带有边缘和彩色区域的背景
- spring-security - Spring Security SAML2 服务提供者 - RelyingPartyRegistration.entityId() vs RelyingPartyRegistration.assertingPartyDetails(c -> c.entityId())
- python - 使用 python 和 selenium 进行自动化 - 每次访问都会更改框架名称
- xamarin - 如何减少 Xamarin 表单中的文本输入显示长度?
- html - VSCode:点击快捷方式时停止选择空格