Sometimes, the log output will be sorted according to the time, such as "20140821\trace.log", in Enterprise Library through the tool configuration, can only define the log file name, You can modify the Flatfiletracelistenerdata implementation by code or the custom Trace listener way,
The code to modify the Flatfiletracelistenerdata implementation code is as follows:
Public Static stringGettracelogpath (stringListenersname) {string_tracepath =string. Empty;if(!string. IsNullOrEmpty (Listenersname)) {Configuration _etlconfig = Configurationmanager.openexeconfigura tion (configurationuserlevel.none); Loggingsettings _loggingsettings = (loggingsettings) _etlconfig.getsection (loggingsettings.sectionname); Flatfiletracelistenerdata _listeners = _loggingsettings.tracelisteners.get (listenersname) asFlatfiletracelistenerdata;if(_listeners! =NULL) {_tracepath = _listeners. FileName; } }return_tracepath; } Public Static voidSettracelogpath (stringListenersname,stringFileName) {if(!string. IsNullOrEmpty (listenersname) &&!string. IsNullOrEmpty (fileName) {Configuration _etlconfig = configurationmanager.openexeconfiguration ( System.Configuration.ConfigurationUserLevel.None); Loggingsettings _loggingsettings = (loggingsettings) _etlconfig.getsection (loggingsettings.sectionname); Flatfiletracelistenerdata _listeners = _loggingsettings.tracelisteners.get (listenersname) asFlatfiletracelistenerdata;if(_listeners! =NULL) {_listeners. filename = filename; _etlconfig.save (); } } }
Test code:
Try{string_listenname ="FlatFile TraceListener"; Settracelogpath (_listenname,string. Format (@ "{0}/trace.log", DateTime.Now.ToString ("YyyyMMdd"))); LogEntry log =NewLogEntry (); Log. Categories.add ("Warning"); Log. Title ="Test"; Log. Message ="Log log Contents"; Logger.write (log); LogEntry log2 =NewLogEntry (); Log2. Categories.add ("Warning"); Log2. Title ="Test 2"; Log2. Message ="Log log content 2"; Logger.write (LOG2); Console.WriteLine (Gettracelogpath (_listenname)); }Catch(Exception ex) {Console.WriteLine (ex. Message); }finally{Console.ReadLine (); }
Test results:
I hope it helps.