tags:

views:

302

answers:

3

I was just wondering if there is any way to encrypt or secure the log4net?

+5  A: 

I'm assuming you want to encrypt the log's output. In that case you will need to write your own Appender which can handle the encryption. I would suggest figuring out what output mechanism you intend to use without encryption (i.e. FileAppender, EventLogAppender, etc.), and then extend that Appender and override the functionality that actually writes out the output.

The reference documentation on the appenders can be found here.

For instance, extend the FileAppender with an EncryptedFileAppender and override/implement the members you need to in order to hook into the file writing.

Alternatively, you could extend from IAppender and create an appender completely from scratch. That would give you more control, but might require more work if all you're trying to do is encrypt your payload.

Joseph
Thanks for your nice tips. So, you mean, I'd better encrypt my content before appending to my logs by implementing a wrapper that does the job. Then, content of my logss would be all encrypted without configuring anything in the log4net?
paradisonoir
You should be able to hook into where it actually appends each line item to the log file, which allows you to encrypt that entire line. Once you've accomplished that, then you would need to configure log4net to use your Appender instead of whatever you were using before. In this case the EncryptedFileAppender
Joseph
@Joseph, are you suggesting to encrypt it for each line of logs, or when it rolls over to a different file (as it reaches the maximum size of logs)?
paradisonoir
@paradisonoir Whichever is your preference. Remember that whatever choice you make you will have to have identical functionality to be able to decrypt.
Joseph
+1  A: 

If you are attempting to prevent users from reading it over the web, you can change the filename you are writing the log records in to an extension which you do not allow to be served by your website. This way, users cannot guess at your log file and access it over the web.

If you are trying to prevent users logged on to the server itself from viewing the contents of the file, you could use permission control to lock the file down so that only users in specific administrator groups could view the contents.

Alternatively, you can log to the database so that there is no file that needs to be secured at all.

Jay S
+1  A: 

There's no out-of-the-box support for encryption. So as others have stated here, you will have to implement that yourself.

That said, I would suggest subclassing a ForwardingAppender to do the encryption. This will basically let you put your appender "in front of" whatever standard appender you would choose to do the actual writing to disk.

Peter Lillevold