.NET(4.0 - C#)的可靠加密日志记录?
我对 C# 比较陌生,所以请耐心等待。我正在为我的项目(桌面小型企业应用程序)寻找日志记录解决方案。我知道这个问题已经被问过无数次了,但我还有一些额外的要求和问题。
.NET 是否有一个日志记录工具(以下所有):
-可靠(记录发送到记录器的所有内容,甚至是崩溃前的最后一个异常,log4net 不保证)
-fast (不阻塞调用者 -> 异步)
-线程安全(可以同时从多个线程调用并写入一个文件)
-加密日志文件(或允许完全自定义日志记录 - 只写入它所需要的内容)获取,没有附加信息)
-免费
嗯,这是我的要求列表。您知道哪些收费标准适合吗?我读过有关 log4net 的内容,但它似乎很旧(使用 .NET 2.0 并且主要是重新发明轮子),nlog 听起来很有前途,因为它是异步的,但我再次认为它无法加密。我也不知道它们是否都是完全线程安全的。
我应该写自己的小记录器吗?我考虑过创建一个日志线程,一个日志列表(或队列),并使用锁定追加到列表中适当的日志,日志线程将转换(可能为字符串,或某些部分为字符串)日志对象,加密它们并保存它们尽快归档。
你认为我应该做什么? 感谢您的想法和答案。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用Microsoft Enterprise Library 5.0 日志记录。您可以使用 MSMQ 目标来使其完全异步。使用加密件,您有几个选择。
创建您自己的侦听器,它将加密发送的消息,或者您可以在发送之前对其进行加密。创建自己的侦听器的几个好处是
使用 ent lib 的主要缺点是,如果您使用起来很复杂,那么配置通常可以是 PIA。
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
The major downside of using ent lib is the configuration in general can be a PIA if you get complicated with it.
NLog仍然被保留,与Log4Net相反。是的,它是线程安全的。
请参阅我的帖子。
您只需要根据您的用例场景知道如何正确使用它即可。
就加密而言,NLog 具有很强的可扩展性,您可以编写自己的日志目标,在将内容发送到文件(或其他)之前对其进行加密。有很多库提供了这样的实用程序(RSA 等)。
您可以在将内容发送到日志实用程序之前对加密服务中的内容进行无缝加密。本身。这是一个起始代码示例,取自这篇文章
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