Logging application block: Flat File Listener: Dinamic file path

Topics: Logging Application Block
Jul 11, 2008 at 1:03 PM
I am developing one application. It works as a batch program and scheduled daily some N  times. I want to store all log files in the format
 {Some Path}\{Time Stamp}\Log.log. 
If it sets 2 times per day, my log files should be,
c:\MyApplicationLogs\2008-07-11-06-00-013\Log.log,  c:\MyApplicationLogs\2008-07-18-00-29-413\Log.log.

 Is there any way to do by changing configuration settings? i can do by code but i want using configuration settings , like in log item template "TimeStamp".

--
Thanks in advance.
Rajesh A
Jul 11, 2008 at 3:05 PM
Hi,

Do you want the timestamp reflect when the program was started or when the log request was performed? If you want the former and you're using v4.0, you could take advantage of the Flat file listener's ability to use environment variables in to determine the log file path. With that approach your either your batch scheduler or your app could set the environment variable to whatever you need before the first log request.

On the other hand, if you need the log file to reflect the time when the logging request was made then you'll need a custom trace listener; there is no support for this in the standard one.

Hope this helps,
Fernando


rajeshaz09 wrote:
I am developing one application. It works as a batch program and scheduled daily some N  times. I want to store all log files in the format
 {Some Path}\{Time Stamp}\Log.log. 
If it sets 2 times per day, my log files should be,
c:\MyApplicationLogs\2008-07-11-06-00-013\Log.log,  c:\MyApplicationLogs\2008-07-18-00-29-413\Log.log.

 Is there any way to do by changing configuration settings? i can do by code but i want using configuration settings , like in log item template "TimeStamp".

--
Thanks in advance.
Rajesh A


Jul 15, 2008 at 1:01 AM
Can the log file path be set in the application by passing a parameter ?
Jul 15, 2008 at 1:13 AM
Yes, but of couse not automatically. You'd need to set an environment variable with the parameter's value, which would require your program to have the proper security permissions.

Fernando

AgentM wrote:
Can the log file path be set in the application by passing a parameter ?


Jul 15, 2008 at 5:02 PM

LogWriter

 

logwriter=null;
FileConfigurationSource source=new FileConfigurationSource ( @"C:\Configuration\myapp.config" );
LogWriterFactory factory=new LogWriterFactory ( source );
logwriter=factory.Create ();
LogEntry Log = new LogEntry ();
Log.Message = "test";
Log.Categories.Add("General");
Log.Priority = 2
;
logwriter.Write ( Log );

I am using the above code with the FileConfigurationSource, all my Tracelistners, categories are defined in the config file.
The code doesn't generate any log entries what am I missing?

 

Jul 15, 2008 at 10:00 PM
this is the error I get in the Logging block's source code.

"An error occurred creating the configuration section handler for loggingConfiguration: Could not load file or assembly 'Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040) (C:\Configuration\myapp.config line 4)"

What am I missing ? any help appreciated.
Jul 16, 2008 at 3:37 PM
The versions of your assemblies are mixed-up. Please look for solutions to this issue by searching for "0x80131040" in this discussion list.

Fernando


AgentM wrote:
this is the error I get in the Logging block's source code.

"An error occurred creating the configuration section handler for loggingConfiguration: Could not load file or assembly 'Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040) (C:\Configuration\myapp.config line 4)"

What am I missing ? any help appreciated.