根據標題,我有一個以 DLL 形式提供的第三方庫,這些 DLL 依賴于也提供的 NLog.dll (4.3.5)。當我嘗試從 .NET 6 客戶端啟動庫時,出現以下例外。“找不到方法:System.String System.AppDomainSetup.get_ConfigurationFile()”。顯然,NLog 正在尋找一個組態檔,該檔案過去應該在 App.config 檔案中。在互聯網上搜索似乎可以通過呼叫 NLog API 來提供組態檔,但我無法這樣做,因為我無法訪問底層 API。有人知道讓這個設定作業的方法嗎?
uj5u.com熱心網友回復:
盡管您對 App.config 的看法是正確的,但還有其他選項,例如我有一個使用 Nlog 的 .net 6 應用程式。我使用的組態檔稱為 NLog.config(和 NLog.dev.config)。完整的細節在 NLog 組態檔檔案https://github.com/NLog/NLog/wiki/Configuration-file
uj5u.com熱心網友回復:
錯誤發生在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
所以我對你使用這個舊版本不抱太大希望。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/399943.html
上一篇:了解.Net中的異步和等待
下一篇:如何將IntPtr轉換為結構陣列
