當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。