robbie
robbie

Reputation: 668

How can I catch the event when a log file rolls over in Log4Net so that I can do some further action?

Basically, this is what I am trying to do. I am using Log4Net and rolling over the log files each day and appending the file name with the date.

I'd like to catch the event that begins the rolling over action so that I can perform another task right after the rollover finishes.

Specifically, I am trying to encrypt the file immediately after it rolls over.

Any help would be greatly appreciated. Thanks in advance!

Upvotes: 2

Views: 768

Answers (2)

Sam Corder
Sam Corder

Reputation: 5422

If you're doing nothing but leaving the encrypted file on the server then I see a flaw in your setup. You will always have the current day's data sitting in plain text on your server. Since it is all just streams I bet it would be easy to inherit from the RollingFileAppender and replace its output stream with something wrapped in an encrypted stream.

Upvotes: 1

Ryan Bennett
Ryan Bennett

Reputation: 3432

You can always imploy a file watcher on a seperate thread for your log directory. When it sees a new file, encrypt the last one. I can't find any rollover event for log4net, but this should be pretty quick for your needs.

http://msdn.microsoft.com/en-us/library/system.io.filesystemwatcher.aspx

Upvotes: 0

Related Questions