简体   繁体   English

模板Log4Net配置

[英]Template Log4Net Configuration

I'm trying to simplify our log4net configuration across a number of projects. 我正在尝试简化许多项目的log4net配置。

We have multiple services which all create logs. 我们有多种服务都可以创建日志。 Their appenders are defined in each services app.config. 它们的附加程序在每个服务app.config中定义。 This creates a lot of repetition. 这会产生很多重复。

I'd like to shift the log4net configuration out of here and into a Log4NetConfiguration.config file I can link to from each project similar to the accepted answer in this question: 我想将log4net配置移出这里,并移到一个Log4NetConfiguration.config文件中,我可以从每个项目链接到该文件,类似于该问题中可接受的答案:

Share log4net configuration across multiple projects 在多个项目中共享log4net配置

This way when developing we only need to change configuration in one place - but users can configure different services log files as they choose. 这样,在开发时,我们只需要在一个地方更改配置-但用户可以根据自己的选择配置不同的服务日志文件。

We call log4net.Config.XmlConfigurator.Configure() from a common utilities assembly - how do I get this to load the relevant version of Log4NetConfiguration.config from the running service? 我们从通用实用程序程序集调用log4net.Config.XmlConfigurator.Configure()-如何从正在运行的服务中加载Log4NetConfiguration.config的相关版本?

As per StuartD's comment it's in the bin directory. 根据StuartD的评论,它位于bin目录中。

As such, you can just use Assembly.GetExecutingAssembly().Location to get the location of the config file relevant for the running application. 这样,您可以只使用Assembly.GetExecutingAssembly()。Location来获取与正在运行的应用程序相关的配置文件的位置。

Then use XmlConfigurator.ConfigureAndWatch(fileInfo) as suggested. 然后根据建议使用XmlConfigurator.ConfigureAndWatch(fileInfo)。

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

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