NLog:强制BufferingTargetWrapper在AppDomain UnhandledException上为空 [英] NLog: Force BufferingTargetWrapper to empty on AppDomain UnhandledException
问题描述
我在我的应用程序中将NLog配置为使用BufferingTargetWrapper
与MailTarget
发送电子邮件.
I have NLog configured in my application to to use the BufferingTargetWrapper
for sending emails with the MailTarget
.
我遇到的问题是,在应用程序从未处理的异常退出之前,我找不到强制NLog清空BufferingTargetWrapper
的方法.
The problem I'm running into is I can not find a way to force NLog to empty the BufferingTargetWrapper
before the application exits from Unhandled Exceptions.
我尝试从当前应用程序域的UnhandledException事件中调用LogManager.Flush()
和LogManager.DisableLogging()
,但是它无法正常工作.
I tried calling LogManager.Flush()
and LogManager.DisableLogging()
from the Current App Domain's UnhandledException Event but it does not seam to work.
我需要怎么做才能使其发送电子邮件?
What would I need to do to make it send the emails?
推荐答案
,您可以调用BufferingTargetWrapper并强制其写入日志. LogManger.Flush无法正常工作很奇怪.
you can call the BufferingTargetWrapper and force it to write the logs. Its strange that the LogManger.Flush doesn't work.
var buffWapper =
LogManager.Configuration.FindTargetByName("BufferingTargetWrapper") as BufferingTargetWrapper;
if (buffWapper != null)
buffWapper.Flush();
或
var buffWapper =
LogManager.Configuration.FindTargetByName("BufferingTargetWrapper") as BufferingTargetWrapper;
if (buffWapper != null)
{
buffWapper.BufferSize = 1;
buffWapper.Flush();
}
这篇关于NLog:强制BufferingTargetWrapper在AppDomain UnhandledException上为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!