Joshua Mee
Joshua Mee

Reputation: 602

Template Log4Net Configuration

I'm trying to simplify our log4net configuration across a number of projects.

We have multiple services which all create logs. Their appenders are defined in each services 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:

Share log4net configuration across multiple projects

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?

Upvotes: 1

Views: 529

Answers (1)

Joshua Mee
Joshua Mee

Reputation: 602

As per StuartD's comment it's in the bin directory.

As such, you can just use Assembly.GetExecutingAssembly().Location to get the location of the config file relevant for the running application.

Then use XmlConfigurator.ConfigureAndWatch(fileInfo) as suggested.

Upvotes: 1

Related Questions