当日志文件在 Log4Net 中滚动时,如何捕获事件,以便我可以执行进一步的操作?
基本上,这就是我正在尝试做的事情。我正在使用 Log4Net 并每天滚动日志文件并在文件名后附加日期。
我想捕获开始滚动操作的事件,以便我可以在滚动完成后立即执行另一个任务。
具体来说,我试图在文件翻转后立即对其进行加密。
任何帮助将不胜感激。提前致谢!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您除了将加密文件保留在服务器上之外什么也不做,那么我会发现您的设置存在缺陷。您的服务器上始终会以纯文本形式保存当天的数据。由于它只是流,我敢打赌,从 RollingFileAppender 继承并用加密流中包含的内容替换其输出流会很容易。
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.
您始终可以在日志目录的单独线程上使用文件观察器。当它看到新文件时,加密最后一个文件。我找不到 log4net 的任何翻转事件,但这应该很快就能满足您的需求。
http://msdn.microsoft.com/en-us/library /system.io.filesystemwatcher.aspx
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