当前位置: 首页>>代码示例>>C#>>正文


C# Common.AsyncLogEventInfo类代码示例

本文整理汇总了C#中NLog.Common.AsyncLogEventInfo的典型用法代码示例。如果您正苦于以下问题:C# AsyncLogEventInfo类的具体用法?C# AsyncLogEventInfo怎么用?C# AsyncLogEventInfo使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


AsyncLogEventInfo类属于NLog.Common命名空间,在下文中一共展示了AsyncLogEventInfo类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Write

        /// <summary>
        /// Writes the provided <see cref="AsyncLogEventInfo"/> to the underlying target.
        /// </summary>
        /// <param name="logEvent">The log event to write.</param>
        protected override void Write(AsyncLogEventInfo logEvent)
        {
            // check if current event is different from previous
            if (IsDifferentFromPrevious(logEvent.LogEvent))
            {
                // current event is different - we need to write the count of same as previous messages
                if (_previousLogEvent != null && _previousCount > 0)
                {
                    var e = LogEventInfo.Create(_previousLogEvent.Level,
                                                _previousLogEvent.LoggerName,
                                                CultureInfo.CurrentCulture,
                                                "{0} more of previous message.",
                                                new object[] { _previousCount });

                    WrappedTarget.WriteAsyncLogEvent(new AsyncLogEventInfo(e, ex => { }));
                }

                // reset counters
                _previousLogEvent = logEvent.LogEvent;
                _previousCount = 0;

                // write current event
                WrappedTarget.WriteAsyncLogEvent(logEvent);
            }
            else
            {
                // if current event is same as previous - simply increase the count and don't write it to the wrapped target
                _previousCount++;
            }
        }
开发者ID:ArtiomCiumac,项目名称:upsmonitor,代码行数:34,代码来源:DiscardDuplicatesTargetWrapper.cs

示例2: Enqueue

        /// <summary>
        /// Enqueues another item. If the queue is overflown the appropriate
        /// action is taken as specified by <see cref="OnOverflow"/>.
        /// </summary>
        /// <param name="logEventInfo">The log event info.</param>
        public void Enqueue(AsyncLogEventInfo logEventInfo)
        {
            lock (this)
            {
                if (this.logEventInfoQueue.Count >= this.RequestLimit)
                {
                    switch (this.OnOverflow)
                    {
                        case AsyncTargetWrapperOverflowAction.Discard:
                            // dequeue and discard one element
                            this.logEventInfoQueue.Dequeue();
                            break;

                        case AsyncTargetWrapperOverflowAction.Grow:
                            break;

#if !NET_CF
                        case AsyncTargetWrapperOverflowAction.Block:
                            while (this.logEventInfoQueue.Count >= this.RequestLimit)
                            {
                                InternalLogger.Trace("Blocking...");
                                System.Threading.Monitor.Wait(this);
                                InternalLogger.Trace("Entered critical section.");
                            }

                            InternalLogger.Trace("Limit ok.");
                            break;
#endif
                    }
                }

                this.logEventInfoQueue.Enqueue(logEventInfo);
            }
        }
开发者ID:semirs,项目名称:CellAO,代码行数:39,代码来源:AsyncRequestQueue-T.cs

示例3: Write

        /// <summary>
        /// Forwards the log event to the sub-targets until one of them succeeds.
        /// </summary>
        /// <param name="logEvent">The log event.</param>
        /// <remarks>
        /// The method remembers the last-known-successful target
        /// and starts the iteration from it.
        /// If <see cref="ReturnToFirstOnSuccess"/> is set, the method
        /// resets the target to the first target
        /// stored in <see cref="Targets"/>.
        /// </remarks>
        protected override void Write(AsyncLogEventInfo logEvent)
        {
            Action<Exception> continuation = null;
            int tryCounter = 0;
            int targetToInvoke;

            continuation = ex =>
                {
                    if (ex == null)
                    {
                        // success
                        lock (this.lockObject)
                        {
                            if (this.currentTarget != 0)
                            {
                                if (this.ReturnToFirstOnSuccess)
                                {
                                    InternalLogger.Debug("Fallback: target '{0}' succeeded. Returning to the first one.", this.Targets[this.currentTarget]);
                                    this.currentTarget = 0;
                                }
                            }
                        }

                        logEvent.Continuation(null);
                        return;
                    }

                    // failure
                    lock (this.lockObject)
                    {
                        InternalLogger.Warn("Fallback: target '{0}' failed. Proceeding to the next one. Error was: {1}", this.Targets[this.currentTarget], ex);

                        // error while writing, go to the next one
                        this.currentTarget = (this.currentTarget + 1) % this.Targets.Count;

                        tryCounter++;
                        targetToInvoke = this.currentTarget;
                        if (tryCounter >= this.Targets.Count)
                        {
                            targetToInvoke = -1;
                        }
                    }

                    if (targetToInvoke >= 0)
                    {
                        this.Targets[targetToInvoke].WriteAsyncLogEvent(logEvent.LogEvent.WithContinuation(continuation));
                    }
                    else
                    {
                        logEvent.Continuation(ex);
                    }
                };

            lock (this.lockObject)
            {
                targetToInvoke = this.currentTarget;
            }

            this.Targets[targetToInvoke].WriteAsyncLogEvent(logEvent.LogEvent.WithContinuation(continuation));
        }
开发者ID:ExM,项目名称:NLog,代码行数:71,代码来源:FallbackGroupTarget.cs

示例4: Enqueue

        /// <summary>
        /// Enqueues another item. If the queue is overflown the appropriate
        /// action is taken as specified by <see cref="OnOverflow"/>.
        /// </summary>
        /// <param name="logEventInfo">The log event info.</param>
        public void Enqueue(AsyncLogEventInfo logEventInfo)
        {
            lock (this)
            {
                if (this.logEventInfoQueue.Count >= this.RequestLimit)
                {
                    InternalLogger.Debug("Async queue is full");
                    switch (this.OnOverflow)
                    {
                        case AsyncTargetWrapperOverflowAction.Discard:
                            InternalLogger.Debug("Discarding one element from queue");
                            this.logEventInfoQueue.Dequeue();
                            break;

                        case AsyncTargetWrapperOverflowAction.Grow:
                            InternalLogger.Debug("The overflow action is Grow, adding element anyway");
                            break;

                        case AsyncTargetWrapperOverflowAction.Block:
                            while (this.logEventInfoQueue.Count >= this.RequestLimit)
                            {
                                InternalLogger.Debug("Blocking because the overflow action is Block...");
                                System.Threading.Monitor.Wait(this);
                                InternalLogger.Trace("Entered critical section.");
                            }

                            InternalLogger.Trace("Limit ok.");
                            break;
                    }
                }

                this.logEventInfoQueue.Enqueue(logEventInfo);
            }
        }
开发者ID:xiaopohou,项目名称:NLog,代码行数:39,代码来源:AsyncRequestQueue-T.cs

示例5: Write

 protected override void Write(AsyncLogEventInfo[] logEvents)
 {
     foreach (AsyncLogEventInfo logEvent in logEvents)
     {
         Write(logEvent);
     }
 }
开发者ID:jorgechen,项目名称:CoolFish,代码行数:7,代码来源:RemoteTarget.cs

示例6: Write

        /// <see>
        ///     <cref>TargetWithLayout Write(AsyncLogEventInfo[])</cref>
        /// </see>
        protected override void Write(AsyncLogEventInfo[] logEvents) {
            var bulkSignals = new StringBuilder();

            foreach (var logEvent in logEvents) {
                var eventInfo = logEvent.LogEvent;
                var rawMessage = Layout.Render(eventInfo); 

                var signal = new Signal() {
                    Logger = "NLog",
                    SequenceId = eventInfo.SequenceID,
                    TimeStamp = eventInfo.TimeStamp,
                    LogLevel = eventInfo.Level.Name,
                    LogLevelOrdinal = eventInfo.Level.Ordinal,
                    LoggerName = eventInfo.LoggerName,
                    Message = eventInfo.Message,
                    FormattedMessage = eventInfo.FormattedMessage,
                    StackTrace = eventInfo.StackTrace,
                    RawMessage = rawMessage
                };

                bulkSignals.Append(string.Concat(JsonConvert.SerializeObject(signal), "\n"));
            }

            var url = new Uri(string.Format("{0}/{1}/{2}/{3}", ServiceUrl, ApiKey, SignalType, Tags));

            var client = new WebClient();
            client.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
            client.Headers.Add("cloudish-bulk", "true");
            client.UploadStringAsync(url, "POST", bulkSignals.ToString());
        }
开发者ID:Cloudish-OSS,项目名称:Cloudish.LoggingExtensions,代码行数:33,代码来源:SignalTarget.cs

示例7: Write

        protected override void Write(AsyncLogEventInfo logEvent)
        {
            var continuation = logEvent.Continuation;
            var message = GetMessage(logEvent);

            if (null == _queueClient || _queueClient.IsClosed)
            {
                CreateNewClient();
            }

            if (null == _queueClient || _queueClient.IsClosed)
            {
                AddMessageToUnsentQueue(message);
            }

            try
            {
                CheckUnsent();
                Publish(message);
            }
            catch (Exception e)//(MessagingException e)
            {
                AddMessageToUnsentQueue(message);
                continuation(e);
            }
        }
开发者ID:jdstuart,项目名称:nlog.targets.azureservicebus,代码行数:26,代码来源:AzureServiceBusQueueTarget.cs

示例8: Write

        ///<summary>
        /// Enqueues the log event; if the log level is the trigger level or more severe, all queued events are written
        /// </summary>
        /// <param name="logEvent"></param>
        protected override void Write(AsyncLogEventInfo logEvent)
        {

            lock (this.SyncRoot)
            {

                _queuedEvents.Enqueue(logEvent);



                if (logEvent.LogEvent.Level >= _triggerLevel)
                {

                    while (_queuedEvents.Count > 0)
                    {

                        this.WrappedTarget.WriteAsyncLogEvent(_queuedEvents.Dequeue());

                    }

                }



                if (_queuedEvents.Count > QueueSize)
                {

                    _queuedEvents.Dequeue();

                }

            }

        }
开发者ID:fxmozart,项目名称:NLog,代码行数:38,代码来源:QueuedWrapperTarget.cs

示例9: Write

        protected override void Write(AsyncLogEventInfo logEvent)
        {
            base.Write(logEvent);

            string asyncBody = Layout.Render(logEvent.LogEvent);

            PublishToSignalR.WriteToQueue(GetFromNLogLogLevel(logEvent.LogEvent.Level), asyncBody);
        }
开发者ID:Hdesai,项目名称:NLogToSignalR,代码行数:8,代码来源:SignalRTarget.cs

示例10: LogEventMsgSet

 public LogEventMsgSet(AsyncLogEventInfo asyncLogEvent, ByteArray buffer, MessageBuilder messageBuilder, MessageTransmitter messageTransmitter)
 {
     this.asyncLogEvent = asyncLogEvent;
     this.buffer = buffer;
     this.messageBuilder = messageBuilder;
     this.messageTransmitter = messageTransmitter;
     currentMessage = 0;
 }
开发者ID:graffen,项目名称:NLog.Targets.Syslog,代码行数:8,代码来源:LogEventMsgSet.cs

示例11: Write

        protected override void Write(AsyncLogEventInfo logEvent)
        {
            base.Write(logEvent);

            if (Interlocked.Exchange(ref _state, 2) <= 0)
            { // Timer was idle. Starting.
                base.StartLazyWriterTimer();
            }
        }
开发者ID:mike-tesch,项目名称:Sonarr,代码行数:9,代码来源:SlowRunningAsyncTargetWrapper.cs

示例12: WritesMessage

 public void WritesMessage()
 {
     using (var textWriter = new StringWriter())
     using (var instance = new TextWriterNLogTarget(textWriter))
     {
         var logEventInfo = new LogEventInfo(LogLevel.Debug, "UNITTEST", "MESSAGE");
             var logEvent = new AsyncLogEventInfo(logEventInfo, exception => { });
             instance.WriteAsyncLogEvent(logEvent);
             instance.Flush(exception => { });
     }
 }
开发者ID:DHGMS-Solutions,项目名称:logintegrations,代码行数:11,代码来源:TextWriterNLogTargetTests.cs

示例13: TestEquals

 public void TestEquals()
 {
     var logEvent1 = new LogEventInfo(LogLevel.Debug, "logger1", "message1");
     AsyncContinuation cont1 = new AsyncContinuation(exception => { });
     var async1 = new AsyncLogEventInfo(logEvent1, cont1);
     var async2 = new AsyncLogEventInfo(logEvent1, cont1);
     Assert.True(async1.Equals(async2));
     Assert.True(async1 == async2);
     Assert.False(async1 != async2);
     Assert.Equal(async1.GetHashCode(), async2.GetHashCode());
 }
开发者ID:daniefer,项目名称:NLog,代码行数:11,代码来源:AsyncLogEventInfoTests.cs

示例14: Write

 protected override void Write(AsyncLogEventInfo info)
 {
     try
     {
         this.SendToSlack(info);
     }
     catch (Exception e)
     {
         info.Continuation(e);
     }
 }
开发者ID:philjones,项目名称:NLogToSlack,代码行数:11,代码来源:SlackTarget.cs

示例15: Write

        /// <summary>
        /// The write.
        /// </summary>
        /// <param name="logEvent">
        /// The log event.
        /// </param>
        protected override void Write(AsyncLogEventInfo logEvent)
        {
            using (var client = AWSClientFactory.CreateAmazonDynamoDBClient(this.AmazonAccessKeyId, this.AmazonSecretAccessKey))
            {
                var table = Table.LoadTable(client, "TdService_Logs");
                var log = this.CreateLogDocument(logEvent.LogEvent);

                table.BeginPutItem(log, ar => { }, null);
            }

            base.Write(logEvent);
        }
开发者ID:Naviam,项目名称:Shop-Any-Ware,代码行数:18,代码来源:NLogAmazonDynamoDbTarget.cs


注:本文中的NLog.Common.AsyncLogEventInfo类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。