Application Name in Logfile Name

Topics: Logging Application Block
Oct 13, 2014 at 1:40 PM
Hello,

I would like to use the Rolling File Appender to store Logs of several applications in the same Folder.
Therefore I would like to create a config, where the filename for the Log is composed using the application name and the timestamp.

Further, I would like the Tracer to create a new log file, every time the application is started (in addition to the "defaul" rolling).

Does this work out of the box, or do I need to extend/create a Tracer?
Oct 14, 2014 at 7:11 AM
If you are using XML configuration you wouldn't be able to set the timestamp in the file name. You could set the application name but this would require having a separate configuration file for each application with the desired application name set as part of the fileName.

Another approach would be to use programmatic configuration to set the applicable values at application startup.

I'm not sure exactly what the exact scenario is for Tracer but you could write startup code that "archives" the current log file so that a new file is always used at startup.


~~
Randy Levy
entlib.support@live.com
Enterprise Library support engineer
Support How-to
Oct 14, 2014 at 9:03 AM
I solved the app name using Environment variables.
Having such an unflexible filename is still quite a disadvantage compared to other logging frameworks.
Oct 14, 2014 at 5:10 PM
Environment variables are another option. Enterprise Library expands environment variables but %Date% or %Time% are dynamic and the method Environment.ExpandEnvironmentVariables does not expand these.

However, you could configure a custom environment variable in the config (e.g. %MyDate%) and then at startup ensure the file is not present (based on naming in the config -- this could even be read from the config file if desired). If the file is present archive the existing file, then set an environment variable expected by the fileName config:
Environment.SetEnvironmentVariable("MyDate", DateTime.Now.ToString("yyyy-MM-dd"));
See http://entlib.codeplex.com/discussions/351760 for a similar discussion.

~~
Randy Levy
entlib.support@live.com
Enterprise Library support engineer
Support How-to