nlog 不适用于类库项目
我有一个使用几个类库项目的 MVC 应用程序。我已经实现了 NLog 来记录所有项目。每个项目(包括类库项目)都有 NLog.config 文件。日志记录对于 MVC 应用程序非常有效,但对于其他类库,根本不会生成日志文件。
我在这里做错了什么吗?我已将所有项目的日志文件设置为在硬编码路径 (D:{project_name}\xx) 处生成。
另外,我确保所有“NLog.config”文件都设置为“始终复制”到输出目录。
I have an MVC application that uses a couple of class library projects. I have implemented NLog for logging across all the projects. Each project (including the class library projects) have the NLog.config file. Logging works great for the MVC application, however for the other class libraries the log files do not get generated at all.
Am I doing something wrong here? I have set log files to be generated at a hardcoded path (D:{project_name}\xx) for all the projects.
Also, I have ensured that all the "NLog.config" files are set to "Copy Always" to the output directory.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一般来说,我的理解是整个应用程序只使用一个配置文件。因此,每个类库将使用应用程序的配置文件,而不是您为每个类库创建的配置文件。我认为有一些方法可以强制类库查找自己的配置文件,但这并不像访问应用程序的配置文件那么常见。我不确定这是否适用于 NLog,因为只有一个“NLog 实例”(可能不是最准确的术语)。由于只有一个“NLog”,因此只能以一种方式进行配置。
您没有(或不想)将所有 NLog 配置信息放在同一个文件中是否有原因?
Generally speaking, my understanding is that only one config file is used by the entire application. So, each class library will be using the app's config file, not the config file that you created for each class library. I think that there are ways that you can force a class library to look for its own config file, but that is not as common as just accessing the app's config file. I'm not sure that would even work in the case of NLog, since there is only one "NLog instance" (probably not the most accurate terminology). Because there is only one "NLog", it can be configured only one way.
Is there a reason why you didn't (or don't want to) put all of the NLog config information in the same file?