繁体   English   中英

使用依赖于来自 .NET 6 应用程序的 NLog 的第三方库

[英]Using a third party library which depends on NLog from a .NET 6 application

根据标题,我有一个以 DLL 形式提供的第三方库,这些 DLL 依赖于也提供的 NLog.dll (4.3.5)。 当我尝试从 .NET 6 客户端启动库时,出现以下异常。 “找不到方法:System.String System.AppDomainSetup.get_ConfigurationFile()”。 显然,NLog 正在寻找一个配置文件,该文件过去会在 App.config 文件中。 在互联网上搜索似乎可以通过调用 NLog API 来提供配置文件,但我不能这样做,因为我无法访问底层的 API。 有人知道让这个设置工作的方法吗?

尽管您对 App.config 的看法是正确的,但还有其他选项,例如我有一个使用 Nlog 的 .net 6 应用程序。 我使用的配置文件称为 NLog.config(和 NLog.dev.config)。 完整的详细信息在 NLog 配置文件文档https://github.com/NLog/NLog/wiki/Configuration-file

错误发生在NLog.Internal.Fakeables.AppDomainWrapper初始化如下:

public static AppDomainWrapper CurrentDomain => new AppDomainWrapper(AppDomain.CurrentDomain);

然后稍后在 AppDomainWrapper ctor 中:

public AppDomainWrapper(AppDomain appDomain)
{
    BaseDirectory = appDomain.BaseDirectory;
    // SetupInformation.ConfigurationFile doesn't exist in .NET 6
    ConfigurationFile = appDomain.SetupInformation.ConfigurationFile;

NLog 的许多构造函数都在使用这个AppDomainWrapper.CurrentDomain ,每次使用 NLog class 时都会出错。

这是一个不错的 StackTrace:

at NLog.Internal.Fakeables.AppDomainWrapper..ctor(AppDomain appDomain) in NLog\Internal\Fakeables\AppDomainWrapper.cs:line 58
at NLog.Internal.Fakeables.AppDomainWrapper.get_CurrentDomain()
at NLog.LogFactory.get_CurrentAppDomain() in NLog\LogFactory.cs:line 154
at NLog.LogFactory..ctor() in NLog\LogFactory.cs:line 316
at NLog.LogManager..cctor() in NLog\LogManager.cs:line 133

所以我对你使用这个旧版本不抱太大希望。

暂无
暂无

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

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