根据标题,我有一个以 DLL 形式提供的第三方库,这些 DLL 依赖于也提供的 NLog.dll (4.3.5)。当我尝试从 .NET 6 客户端启动该库时,出现以下异常。 “找不到方法:System.String System.AppDomainSetup.get_ConfigurationFile()”。显然,NLog 正在寻找一个配置文件,该文件在过去应该位于 App.config 文件中。在互联网上搜索似乎可以通过调用 NLog API 来提供配置文件,但我无法这样做,因为我无法访问底层 API。有人知道让这个设置工作的方法吗?
最佳答案
错误发生在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 类时都会出错。
这是一个很好的 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
所以我对你使用这个旧版本不抱太大希望。
关于c# - 使用依赖于 .NET 6 应用程序中的 NLog 的第三方库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70538147/