首页 > 解决方案 > 将 Nlog 与 Costura Fody 一起使用时如何解决错误

问题描述

我正在使用 Nlog,最近决定使用 Fody/Costura 将我的 DLL 嵌入到最终的可执行文件中。我注意到,在使用下面推荐的实例声明启动和创建 Logger 时,我在调用 GetCurrentClassLogger 时遇到异常(请参见下面的异常)。如果我卸载 Costura/Fody,异常就会消失。Nlog 会消耗该错误,但每次我启动我的代码时,它都会因该错误而中断,我想解决它。

//recommended logger declaration
private static Logger logger = LogManager.GetCurrentClassLogger();

//exception thrown when calling the instance declaration
Error Error logging version of assembly NLog, Version=4.0.0.0, 
Culture=neutral, PublicKeyToken=5120e14c03d0593c. Exception: 
System.ArgumentException: The path is not of a legal form.
   at System.IO.Path.LegacyNormalizePath(String path, Boolean fullCheck, 
Int32 maxPathLength, Boolean expandShortPaths)
   at System.IO.Path.GetFullPathInternal(String path)
   at System.IO.Path.GetFullPath(String path)
   at System.Diagnostics.FileVersionInfo.GetFullPathWithAssert(String 
fileName)
   at System.Diagnostics.FileVersionInfo.GetVersionInfo(String fileName)
   at NLog.Common.InternalLogger.LogAssemblyVersion(Assembly assembly)

我已经验证,如果没有安装 Fody/Costura,错误就会消失,当安装 Fody/Costura 时,错误会返回。

我想解决错误,并且每次运行代码时都不让 IDE 停止。我也不想忽略特定异常,以防它发生在与 Nlog 无关的其他代码中。抛出的异常是 System.ArgumentException,它可能发生在其他代码中。

标签: c#nlogfody-costura

解决方案


创建 github.com/NLog/NLog/pull/3258 – Rolf Kristensen

因此将在 NLog 4.6.1 中修复。今天或明天发布(取决于时区;)

更新:已发布:https ://www.nuget.org/packages/NLog/4.6.1


推荐阅读