Encrypted Logs

Topics: Logging Application Block
Aug 18, 2009 at 2:22 AM

Has anyone here tried logging a encrypted log on a flatfile? Or is it even possible with the logging block?



Aug 18, 2009 at 7:10 AM


My initial idea here is that it would be possible. You would just need to implement your own logic on encrypting the log message before logging it. To achieve this together with the logging application block, you must create your custom trace listener. Implement a code that will encrypt the log and send the log to the flat file.

Here is a sample code snippet, just to give you an idea.

public class EncryptedFlatFileTraceListener : CustomTraceListener
    private const string LogFileName = "Encrypted.log";

    public override void Write(string message)

    public override void WriteLine(string message)

    public override void TraceData(TraceEventCache eventCache, string source, TraceEventType eventType, int id, object data)
        if (data is LogEntry && this.Formatter != null)
            string formattedMessage = this.Formatter.Format(data as LogEntry);
	   //Encrypt the log message

Valiant Dudan
Global Technology and Solutions
Avanade, Inc.

Aug 18, 2009 at 3:40 PM

Thanks for the answer and the code snippet. I will do what you've suggested.