开发者

Reliable encrypted logging for .NET (4.0 - C#)?

I'm relatively new to C# so please bear with me. I am looking for a logging solution for my project (desktop small business application). I know this has been asked a zillion times, but I have some additional requirements and questions.

Is there a logging tool for .NET which is (all of the following):

-reliable (logging everything that was send to logger, even the very last exception before the crash, log4net doesn't guarantee that)

-fast (not blocking the caller -> asynchronous)

-thread-safe (can be called from multiple threads at the same time and write to one file)

-encrypts log files (or allows totally custom logging - writes only what it gets, no additional information)

-free

Well, that's my list of requirements. Do you know any tolls which fit? I've read about log4net, but it seems old (uses .NET 2.0 and mainly reinvents the wheel), nlog sounds promising as it is asynchronous, yet again I think it can't encrypt. Also I don't know if both of them are totally thread safe.

Should I just write my own little logger? I thought about making a logging thread, a list (or queue) of logs, and using locking append to the list appropriate logs, logging thread would convert (probably to string, or some parts to string) log objects, encrypt them and save them to a file as soon as possible.

What do you think I should do? Thank you for your i开发者_开发知识库deas and answers.


You could use Microsoft Enterprise Library 5.0 logging . You'd can use the MSMQ targeting to get it completely Asynchronous. With the encryption piece you have a couple of options.

Create your own listener which will encrypt messages sent or you can encrypt it before you send. A couple of nice aspects of creating your own listener

  • Sender doesn't have to "know" how to encrypt. This means if your encryption policy changes you have just have to code it in one object.
  • Relatively easily to configure different behavior depending on environment.

The major downside of using ent lib is the configuration in general can be a PIA if you get complicated with it.


NLog is still maintained, on the contrary of Log4Net. And Yes, it IS thread-safe. See my post on that.
You just have to know how to use it correctly according to your use case scenario.

As of Encryption, NLog is very expandable and you can write your own log target that encrypts the content before sending it to files (or other). There are lots of Libraries that offer such a utility (RSA Among others).

You would seamlessly encrypt content in an Encryption Service just before sending it to the log utility per se. Here is a starter code sample, taken from this post

var provider = new System.Security.Cryptography.RSACryptoServiceProvider();
provider.ImportParameters(your_rsa_key);

var encryptedBytes = provider.Encrypt(
System.Text.Encoding.UTF8.GetBytes("Hello World!"), true);

string decryptedTest = System.Text.Encoding.UTF8.GetString(
provider.Decrypt(encryptedBytes, true));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜