WriteAsyncLogEvent() public method

Writes the log to the target.
public WriteAsyncLogEvent ( NLog.Common.AsyncLogEventInfo logEvent ) : void
logEvent NLog.Common.AsyncLogEventInfo Log event to write.
return void
Ejemplo n.º 1
0
        private static bool WriteToTargetWithFilterChain(Targets.Target target, FilterResult result, LogEventInfo logEvent, AsyncContinuation onException)
        {
            if ((result == FilterResult.Ignore) || (result == FilterResult.IgnoreFinal))
            {
                if (InternalLogger.IsDebugEnabled)
                {
                    InternalLogger.Debug("{0}.{1} Rejecting message because of a filter.", logEvent.LoggerName, logEvent.Level);
                }

                if (result == FilterResult.IgnoreFinal)
                {
                    return(false);
                }

                return(true);
            }

            target.WriteAsyncLogEvent(logEvent.WithContinuation(onException));
            if (result == FilterResult.LogFinal)
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 2
0
        private static void AssertOutput(Target target, string message, string[] expectedParts)
        {
            var consoleOutWriter = new PartsWriter();
            TextWriter oldConsoleOutWriter = Console.Out;
            Console.SetOut(consoleOutWriter);

            try
            {
                var exceptions = new List<Exception>();
                target.Initialize(null);
                target.WriteAsyncLogEvent(new LogEventInfo(LogLevel.Info, "Logger", message).WithContinuation(exceptions.Add));
                target.Close();

                Assert.Equal(1, exceptions.Count);
                Assert.True(exceptions.TrueForAll(e => e == null));
            }
            finally
            {
                Console.SetOut(oldConsoleOutWriter);
            }

            var expected = Enumerable.Repeat("Logger " + expectedParts[0], 1).Concat(expectedParts.Skip(1));
            Assert.Equal(expected, consoleOutWriter.Values);
        }