.NET Core Class 带有 NLog 的库,目标是 .Net 4.6.1
.NET Core Class Library with NLog targeting .Net 4.6.1
我目前正在根据我的工作创建一个公共库,该库将使用 NLog 实现抽象记录器。
我创建了一个针对 .NET 4.6.1 的 .NET Core class 库并实现了 NLog,但是当我尝试执行我创建的单元测试时,我注意到nlog.config 文件未被拾取。我也遵循了 https://github.com/NLog/NLog.Extensions.Logging 说明的说明,但我注意到它仅针对 Asp.Net Core 而不是 .NET Core Class 库解决方案。
我的问题是,(考虑到这是我第一次涉足 .NET Core)上面 link 中所述的说明是否也适用于 .Net Core class 库,或者有没有不同的方法来实现这个?
或者我最终应该不使用 .Net Core 而转而使用更传统的 .NET Class 库实现吗?
非常感谢!
I've created a .NET Core class library targeting .NET 4.6.1 and implemented NLog, but when I try to execute a unit test that I've created, I've noticed that the nlog.config file
单元测试时运行很难找到配置文件。不同的框架使用不同的位置。以下选项应该有效
手动查找配置文件位置并将其传递给 NLog。使用
LogManager.Configuration = new XmlLoggingConfiguration(filePath, true);
而不是 ConfigureNLog()
或
- 使用 the API 或
创建配置
将 XML 创建为字符串并将其提供给 NLog:使用
而不是 ConfigureNLog
XElement element = XElement.Parse(configXml);
LogManager.Configuration = new XmlLoggingConfiguration(element.CreateReader(), "nlog.config");
I've noticed that it only targets Asp.Net Core and not for .NET Core Class Library solution.
有或没有 ASP.NET 都适用。 ASP.NET 部分 will be moved to the NLog.Web package in the future
我目前正在根据我的工作创建一个公共库,该库将使用 NLog 实现抽象记录器。
我创建了一个针对 .NET 4.6.1 的 .NET Core class 库并实现了 NLog,但是当我尝试执行我创建的单元测试时,我注意到nlog.config 文件未被拾取。我也遵循了 https://github.com/NLog/NLog.Extensions.Logging 说明的说明,但我注意到它仅针对 Asp.Net Core 而不是 .NET Core Class 库解决方案。
我的问题是,(考虑到这是我第一次涉足 .NET Core)上面 link 中所述的说明是否也适用于 .Net Core class 库,或者有没有不同的方法来实现这个?
或者我最终应该不使用 .Net Core 而转而使用更传统的 .NET Class 库实现吗?
非常感谢!
I've created a .NET Core class library targeting .NET 4.6.1 and implemented NLog, but when I try to execute a unit test that I've created, I've noticed that the nlog.config file
单元测试时运行很难找到配置文件。不同的框架使用不同的位置。以下选项应该有效
手动查找配置文件位置并将其传递给 NLog。使用
LogManager.Configuration = new XmlLoggingConfiguration(filePath, true);
而不是
ConfigureNLog()
或- 使用 the API 或 创建配置
将 XML 创建为字符串并将其提供给 NLog:使用
而不是ConfigureNLog
XElement element = XElement.Parse(configXml); LogManager.Configuration = new XmlLoggingConfiguration(element.CreateReader(), "nlog.config");
I've noticed that it only targets Asp.Net Core and not for .NET Core Class Library solution.
有或没有 ASP.NET 都适用。 ASP.NET 部分 will be moved to the NLog.Web package in the future