2

I have NLog configured in my application to to use the BufferingTargetWrapper for sending emails with the MailTarget.

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.

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?

Julian
  • 33,915
  • 22
  • 119
  • 174
RoboDev
  • 4,003
  • 11
  • 42
  • 51
  • Are you using a PostFilteringWrapper? I'd really want to see your .nlog or programmatic configuration. – Mike Post Mar 14 '10 at 11:01
  • I think there is either an extra thread running with the buffer, which doesn't get any timeslice or a pending timer which would need (some) time. did you try some Threading.Thread.Speep(x) ? – ralf.w. Apr 05 '11 at 18:39

1 Answers1

0

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();

or

var buffWapper =
            LogManager.Configuration.FindTargetByName("BufferingTargetWrapper") as BufferingTargetWrapper;
        if (buffWapper != null)
        {
            buffWapper.BufferSize = 1;
            buffWapper.Flush();
        }
Jethro
  • 5,896
  • 3
  • 23
  • 24