<PackageReference Include="NLog" Version="6.2.1" />

NLog.Targets.AsyncTaskTarget

public abstract class AsyncTaskTarget : TargetWithContext
Abstract Target with async Task support
public int BatchSize { get; set; }

Gets or sets the number of log events processed in a single batch.

public bool ForceLockingQueue { get; set; }

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.

public int QueueLimit { get; set; }

Gets or sets the limit on the number of requests in the lazy writer thread request queue.

public int RetryCount { get; set; }

How many attempts to retry the same Task, before it is aborted

public int RetryDelayMilliseconds { get; set; }

How many milliseconds to wait before next retry (will double with each retry)

public int TaskDelayMilliseconds { get; set; }

How many milliseconds to delay the actual write operation to optimize for batching

protected virtual TaskScheduler TaskScheduler { get; }

Task Scheduler used for processing async Tasks

public int TaskTimeoutSeconds { get; set; }

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

protected abstract Task WriteAsyncTask(LogEventInfo logEvent, CancellationToken cancellationToken)

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.