예제 #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);
        }
예제 #2
0
 public LogEventMsgSet(AsyncLogEventInfo asyncLogEvent, ByteArray buffer, MessageBuilder messageBuilder, MessageTransmitter messageTransmitter)
 {
     this.asyncLogEvent = asyncLogEvent;
     this.buffer = buffer;
     this.messageBuilder = messageBuilder;
     this.messageTransmitter = messageTransmitter;
     currentMessage = 0;
 }
예제 #3
0
 public AsyncLogger(Layout loggingLayout, EnforcementConfig enforcementConfig, MessageBuilder messageBuilder, MessageTransmitterConfig messageTransmitterConfig)
 {
     layout = loggingLayout;
     cts = new CancellationTokenSource();
     token = cts.Token;
     throttling = Throttling.FromConfig(enforcementConfig.Throttling);
     queue = NewBlockingCollection();
     buffer = new ByteArray(enforcementConfig.TruncateMessageTo);
     messageTransmitter = MessageTransmitter.FromConfig(messageTransmitterConfig);
     Task.Factory.StartNew(() => ProcessQueueAsync(messageBuilder));
 }
예제 #4
0
        /// <summary>Initializes the SyslogTarget</summary>
        protected override void InitializeTarget()
        {
            base.InitializeTarget();

            if (inited)
                DisposeDependencies();

            messageBuilder = MessageBuilder.FromConfig(MessageCreation, Enforcement);
            asyncLoggers = Enforcement.MessageProcessors.Select(i => new AsyncLogger(Layout, Enforcement, messageBuilder, MessageSend)).ToArray();
            inited = true;
        }