简体   繁体   English

在N层应用程序中自定义日志记录

[英]Custom logging in a N-Tier Application

I have an N-tier application, ASP.Net front end, then a .Net C# Business and Data Access Layer. 我有一个N层应用程序,ASP.Net前端,然后是.Net C#业务和数据访问层。 I have created a simple custom logging library. 我创建了一个简单的自定义日志库。 This logging library is then used throughout my application ie Log.LogException and Log.LogMessage. 然后在我的应用程序中使用此日志记录库,即Log.LogException和Log.LogMessage。

For this logging library I want to define the custom path for the logs folder created by my application. 对于此日志记录库,我想为我的应用程序创建的日志文件夹定义自定义路径。 I initially thought the correct approach was to use an App.Config for my Logging library and then read in the path from there but the problem is that when I publish my Web App to its Target Location it copes all the binaries across including the logging DLL but not the accompanying App.Config. 我最初认为正确的方法是使用App.Config作为我的Logging库,然后从那里读取路径,但问题是,当我将我的Web应用程序发布到其目标位置时,它会处理所有二进制文件,包括日志记录DLL但不是随附的App.Config。

This leads me to believe that this is not the right approach. 这让我相信这不是正确的方法。 I could do some "hack" to copy it across but that is a bad idea if it is not the best design approach. 我可以做一些“黑客”来复制它,但如果它不是最好的设计方法,这是一个坏主意。

Is this a supported design or am I going down the wrong route? 这是一个支持的设计还是我走错了路线?

Thanks! 谢谢!

You need to have your custom path for the logs in the Web App config, or add your custom config to the Web App, which will deploy it when you publish. 您需要在Web App配置中获取日志的自定义路径,或将自定义配置添加到Web App,Web App将在您发布时进行部署。

see here: moving the config files for a dll to the app that calls the dll 看到这里: 将dll的配置文件移动到调用dll的应用程序

However, I'd suggest doing away with your custom logging library entirely, and use something like this: http://nlog-project.org/ 但是,我建议完全取消您的自定义日志库,并使用以下内容: http//nlog-project.org/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM