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 ideas and answers.
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