[英]Using a third party library which depends on NLog from a .NET 6 application
As per the title, I have a third party library supplied in the form of DLLs, these DLLs have a dependency on NLog.dll (4.3.5) which is also supplied.根据标题,我有一个以 DLL 形式提供的第三方库,这些 DLL 依赖于也提供的 NLog.dll (4.3.5)。 When I try and start the library from a .NET 6 client I get the following exception.
当我尝试从 .NET 6 客户端启动库时,出现以下异常。 "Method not found: System.String System.AppDomainSetup.get_ConfigurationFile()".
“找不到方法:System.String System.AppDomainSetup.get_ConfigurationFile()”。 Apparently NLog is looking for a config file which in the past would have been in the App.config file.
显然,NLog 正在寻找一个配置文件,该文件过去会在 App.config 文件中。 Searching the internet it appears one can supply the config file via a call to the NLog API, but I can't do this as I have no access to the underlying API.
在互联网上搜索似乎可以通过调用 NLog API 来提供配置文件,但我不能这样做,因为我无法访问底层的 API。 Does anybody know of a way of getting this setup working?
有人知道让这个设置工作的方法吗?
Although you are correct about App.config there are other options, for exampleI have a .net 6 application that uses Nlog.尽管您对 App.config 的看法是正确的,但还有其他选项,例如我有一个使用 Nlog 的 .net 6 应用程序。 The config file I use is called NLog.config (and NLog.dev.config).
我使用的配置文件称为 NLog.config(和 NLog.dev.config)。 Full details are on the NLog Configuraiton file documentation https://github.com/NLog/NLog/wiki/Configuration-file
完整的详细信息在 NLog 配置文件文档https://github.com/NLog/NLog/wiki/Configuration-file
The error occurs in NLog.Internal.Fakeables.AppDomainWrapper
which is initialized like this:错误发生在
NLog.Internal.Fakeables.AppDomainWrapper
初始化如下:
public static AppDomainWrapper CurrentDomain => new AppDomainWrapper(AppDomain.CurrentDomain);
Then later in AppDomainWrapper ctor:然后稍后在 AppDomainWrapper ctor 中:
public AppDomainWrapper(AppDomain appDomain)
{
BaseDirectory = appDomain.BaseDirectory;
// SetupInformation.ConfigurationFile doesn't exist in .NET 6
ConfigurationFile = appDomain.SetupInformation.ConfigurationFile;
Many Constructors of NLog are using this AppDomainWrapper.CurrentDomain
which will Error every time you use a NLog class. NLog 的许多构造函数都在使用这个
AppDomainWrapper.CurrentDomain
,每次使用 NLog class 时都会出错。
Here is a nice StackTrace:这是一个不错的 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
So i don't have much hope for you using this old version.所以我对你使用这个旧版本不抱太大希望。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.