本文整理汇总了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++;
}
}
示例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);
}
}
示例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));
}
示例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);
}
}
示例5: Write
protected override void Write(AsyncLogEventInfo[] logEvents)
{
foreach (AsyncLogEventInfo logEvent in logEvents)
{
Write(logEvent);
}
}
示例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());
}
示例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);
}
}
示例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();
}
}
}
示例9: Write
protected override void Write(AsyncLogEventInfo logEvent)
{
base.Write(logEvent);
string asyncBody = Layout.Render(logEvent.LogEvent);
PublishToSignalR.WriteToQueue(GetFromNLogLogLevel(logEvent.LogEvent.Level), asyncBody);
}
示例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;
}
示例11: Write
protected override void Write(AsyncLogEventInfo logEvent)
{
base.Write(logEvent);
if (Interlocked.Exchange(ref _state, 2) <= 0)
{ // Timer was idle. Starting.
base.StartLazyWriterTimer();
}
}
示例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 => { });
}
}
示例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());
}
示例14: Write
protected override void Write(AsyncLogEventInfo info)
{
try
{
this.SendToSlack(info);
}
catch (Exception e)
{
info.Continuation(e);
}
}
示例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);
}