NLog.Targets.AsyncTaskTarget
Abstract Target with async Task support
Gets or sets the number of log events processed in a single batch.
Gets or sets whether to use the locking queue, instead of a lock-free concurrent queue
The locking queue is less concurrent when many logger threads, but reduces memory allocation
Gets or sets the action to be taken when the lazy writer thread request queue count
exceeds the set limit.
Gets or sets the limit on the number of requests in the lazy writer thread request queue.
How many attempts to retry the same Task, before it is aborted
How many milliseconds to wait before next retry (will double with each retry)
How many milliseconds to delay the actual write operation to optimize for batching
Task Scheduler used for processing async Tasks
How many seconds a Task is allowed to run before it is cancelled.
When the task timeout window expires, any remaining retries will be skipped,
but each retry attempt gets a fresh timeout window.
protected AsyncTaskTarget()
Constructor
protected virtual bool RetryFailedAsyncTask(Exception exception, CancellationToken cancellationToken, int retryCountRemaining, out TimeSpan retryDelay)
Handle cleanup after failed write operation
Override this to provide async task for writing a single logevent.
Example of how to override this method, and call custom async method
protected override Task WriteAsyncTask(LogEventInfo logEvent, CancellationToken token)
{
return CustomWriteAsync(logEvent, token);
}
private async Task CustomWriteAsync(LogEventInfo logEvent, CancellationToken token)
{
await MyLogMethodAsync(logEvent, token).ConfigureAwait(false);
}
protected virtual Task WriteAsyncTask(IList<LogEventInfo> logEvents, CancellationToken cancellationToken)
Override this to provide async task for writing a batch of logevents.