Dynamically assign fileName to a RollingFlatFileTraceListener

Sep 23, 2010 at 8:29 PM


Ive got a requirement whereby I'd like to log to a file but be able to change the file name from within code. Im guessing this is possible but I haven't been able to find a way yet. 


Sep 24, 2010 at 12:31 AM

Enterprise Library 5.0 comes with the Fluent Configuration API which allows you to modify your config during runtime.   In the sample code posted in the link, the line:

  = EnterpriseLibraryContainer.CreateDefaultContainer(configSource);

essentially replaces the configuration file being used by your application.  This is optional.  If you simply want to be able to log to a different file name using the same trace listener, you can use

LogWriterFactory logFactory = new LogWriterFactory(configSource);

LogWriter logWriter = logFactory.CreateDefault();


Another approach is to use the code posted here.


Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.