예제 #1
0
        private void ProcessQueueAsync(MessageBuilder messageBuilder)
        {
            if (token.IsCancellationRequested)
                return;

            var asyncLogEventInfo = queue.Take(token);
            var logEventMsgSet = new LogEventMsgSet(asyncLogEventInfo, buffer, messageBuilder, messageTransmitter);

            logEventMsgSet
                .Build(layout)
                .SendAsync(token)
                .ContinueWith(t =>
                {
                    if (t.IsCanceled)
                    {
                        InternalLogger.Debug("Task canceled");
                        return;
                    }
                    if (t.Exception != null) // t.IsFaulted is true
                        InternalLogger.Debug(t.Exception.GetBaseException(), "Task faulted");
                    else
                        InternalLogger.Debug($"Successfully sent message '{logEventMsgSet}'");
                    ProcessQueueAsync(messageBuilder);
                }, token, TaskContinuationOptions.ExecuteSynchronously, TaskScheduler.Current);
        }
        private Task ProcessQueueAsync(MessageBuilder messageBuilder, TaskCompletionSource <object> tcs)
        {
            if (token.IsCancellationRequested)
            {
                tcs.SetCanceled();
                return(tcs.Task);
            }

            try
            {
                var asyncLogEventInfo = queue.Take(token);
                var logEventMsgSet    = new LogEventMsgSet(asyncLogEventInfo, buffer, messageBuilder, messageTransmitter);
                logEventMsgSet
                .Build(layout)
                .SendAsync(token)
                .ContinueWith(t =>
                {
                    var exception = t.Exception;
                    if (token.IsCancellationRequested || t.IsCanceled)
                    {
                        InternalLogger.Debug("[Syslog] Task canceled");
                        tcs.SetCanceled();
                        return;
                    }
                    if (exception != null)     // t.IsFaulted is true
                    {
                        InternalLogger.Warn(exception.GetBaseException(), "[Syslog] Task faulted");
                    }
                    else
                    {
                        InternalLogger.Debug("[Syslog] Successfully handled message '{0}'", logEventMsgSet);
                    }
                    ProcessQueueAsync(messageBuilder, tcs);
                }, CancellationToken.None, TaskContinuationOptions.ExecuteSynchronously, TaskScheduler.Current);

                return(tcs.Task);
            }
            catch (Exception exception)
            {
                tcs.SetException(exception);
                return(tcs.Task);
            }
        }
        private Task ProcessQueueAsync(MessageBuilder messageBuilder, TaskCompletionSource <object> tcs)
        {
            if (token.IsCancellationRequested)
            {
                return(tcs.CanceledTask());
            }

            try
            {
                var asyncLogEventInfo = queue.Take(token);
                SignalFlushCompletionWhenIsMarker(asyncLogEventInfo);
                var logEventMsgSet = new LogEventMsgSet(asyncLogEventInfo, buffer, messageBuilder, messageTransmitter);

                logEventMsgSet
                .Build(layout)
                .SendAsync(token)
                .ContinueWith(t =>
                {
                    if (t.IsCanceled)
                    {
                        InternalLogger.Debug("Task canceled");
                        tcs.SetCanceled();
                        return;
                    }
                    if (t.Exception != null)     // t.IsFaulted is true
                    {
                        InternalLogger.Warn(t.Exception.GetBaseException(), "Task faulted");
                    }
                    else
                    {
                        InternalLogger.Debug("Successfully sent message '{0}'", logEventMsgSet);
                    }
                    ProcessQueueAsync(messageBuilder, tcs);
                }, token, TaskContinuationOptions.ExecuteSynchronously, TaskScheduler.Current);

                return(tcs.Task);
            }
            catch (Exception exception)
            {
                return(tcs.FailedTask(exception));
            }
        }