编辑log4net的消息之前,他们到达追加程序 [英] Editing Log4Net messages before they reach the appenders

查看:201
本文介绍了编辑log4net的消息之前,他们到达追加程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个安全工具,它通过电子邮件向用户发送他们的新密码。生产电子邮件模块(即我不拥有,不希望改变)将使用log4net的时候门槛详细日志整个HTML电子邮件正文。由于电子邮件包含域用户的明文密码,我想从日志消息删除密码到达追加程序之前。

I have a security tool that sends users their new password through email. The production email module (that I don’t own and don’t want to change) will log the entire html email message body using Log4Net when the threshold is VERBOSE. Since the email contains a domain user’s password in clear text, I would like to remove the password from the log messages before it reaches the appenders.

有没有适合我的方式临时对象插入log4net的堆叠,让我搜索LoggingEvent所消息,并改变它屏蔽掉,我觉得任何密码?我想插入对象,调用邮件模块,然后取出异物。

Is there a way for me to temporary insert an object into the Log4Net stack that would allow me to search the LoggingEvent message and alter it to mask out any passwords that I find? I’d like to insert the object, call the email module, and then remove the object.

推荐答案

我可能会写一个模式转换器。你可以找到一个示例的这里。您的实现可能是这样的:

I would probably write a pattern converter. You can find an example here. Your implementation could be like this:

protected override void Convert(TextWriter writer, LoggingEvent loggingEvent)
{
    string msg = loggingEvent.RenderedMessage;
    // remove the password if there is any
    writer.Write(msg);
}

这篇关于编辑log4net的消息之前,他们到达追加程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆