Halaster
Halaster

Reputation: 1502

Dynamically change log target file using Enterprise Logging

So I'm trying to use enterprise logging in an application, and I want it to have multiple files, so far I have the following in my app.config file:

<add name="Normal" fileName="C:\MyApp\Logs.log" .../>

And in my code I'm simply using

Logging.Write("My log here");

Now what if I want to programatically change the file where it's being logged to C:\MyApp\MyDateHere_Logs.log, how could I approach this?

Haven't found a lot of solutions online. Thanks beforehand.

Upvotes: 1

Views: 1806

Answers (1)

Halaster
Halaster

Reputation: 1502

In the end I ended up creating a custom trace listener of my own and then changing the filename attribute on runtime by following the guide here.

You can access the attribute which stores your path by using Attribute["filename"] (assuming the attribute in your config file's trace listener node has the path in an attribute named "filename".)

Upvotes: 1

Related Questions