简体   繁体   English

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

[英]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.

相关问题 使用第三方库(带有反射)的.NET应用程序。 - .NET application using third-party library (with reflection) older .NET version 从第三方应用程序调用类库时缺少MissingMethodException - MissingMethodException when calling to a class library from third-party application 如何在不使用 .Net 中的第三方库的情况下进行拼写检查 - How to Spell Check without using third party library in .Net 使用第三方托管发布 ASP.NET 应用程序 - Publishing ASP.NET application using third party hosting 如何在.Net Core 中使用不同的第三方记录器登录到文件? 第三方记录器可能会在应用程序启动时动态更改 - How to log to a file using different third party logger in .Net Core? Third party logger may change dynamically when application starts C#窗口表单应用程序:是否可以在不使用任何第三方库的情况下将pdf转换为位图? - C# Window Form Application: Is there a way to convert pdf into bitmap without using any third party library? Reflection.Emit.ILGenerator :: Emit,来自第三方.net库的调用方法 - Reflection.Emit.ILGenerator::Emit, call method from third party .net library 从第三方应用程序获取列表视图 - Get listview from third party application 如何从MVC 6.0和asp net core应用程序中的第三方rest API获取数据 - How to get data from third party rest API in MVC 6.0 and asp net core application 拒绝客户端代码访问.NET中的第三方库 - Deny client code access to a third-party library in .NET
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM