NLog:强制BufferingTargetWrapper在AppDomain UnhandledException上为空 [英] NLog: Force BufferingTargetWrapper to empty on AppDomain UnhandledException

查看:81
本文介绍了NLog:强制BufferingTargetWrapper在AppDomain UnhandledException上为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用程序中将NLog配置为使用BufferingTargetWrapperMailTarget发送电子邮件.

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屋!

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