Move log to archive

Topics: Logging Application Block
Apr 7, 2014 at 3:08 PM
Hi,

I want to move log file from log folder to archive folder when day end. Already is defined Roll functionality for log file with Fluent API.

Thanks!
Apr 8, 2014 at 5:20 AM
There is no functionality built in to Enterprise Library to move a file to an archive folder. You could either have a scheduled task that archives the log files (e.g. at Midnight), or add some wrapper code around LogWriter.Write to check and archive log files or create a custom trace listener that can archive the log file to the appropriate archive folder.

~~
Randy Levy
entlib.support@live.com
Enterprise Library support engineer
Support How-to
Apr 9, 2014 at 12:05 PM
Thanks a lot for reply!
Apr 10, 2014 at 10:07 AM
Now, I have one more question. :) I need to add username(or anything else) property to log template. What is way to do that?

Again thanks!
Apr 11, 2014 at 1:31 PM
You can either use the ExtendedProperties or a custom LogEntry.

To use ExtendedProperties add the value to the dictionary:
var le = new LogEntry();

le.Categories.Add("General");
le.ExtendedProperties.Add("UserId", "Spongebob");

new LogWriterFactory().Create().Write(le);

And configure the formatter:
Timestamp: {timestamp}{newline}
Message: {message}{newline}
Extended Property User Id: {keyvalue(UserId)}

Another approach is to use a custom LogEntry with a "property" token in the formatter to read the custom property:
    public class MyLogEntry : LogEntry
    {
        public string UserId { get; set;}
    }

    MyLogEntry le = new MyLogEntry();

    le.UserId = "Johnny Test";

    new LogWriterFactory().Create().Write(le);

And then the formatter would look like this:
Timestamp: {timestamp}{newline}
Message: {message}{newline}
Custom User Id: {property(UserId)}

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