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

NLog.Targets.Target

Represents logging target.
protected bool IsInitialized { get; }

Gets a value indicating whether the target has been initialized.

public bool LayoutWithLock { get; set; }

NLog Layout are by default threadsafe, so multiple threads can be rendering logevents at the same time. This ensure high concurrency with no lock-congestion for the application-threads, especially when using AsyncTargetWrapper or AsyncTaskTarget. But if using custom Layout or LayoutRenderer that are not threadsafe, then this option can enabled to protect against thread-concurrency-issues. Allowing one to update to NLog 5.0 without having to fix custom/external layout-dependencies.

Gets the logging configuration this target is part of.

public string Name { get; set; }

Gets or sets the name of the target.

public bool OptimizeBufferReuse { get; set; }

Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit

protected object SyncRoot { get; }

Gets the object which can be used to synchronize asynchronous operations that must rely on the .

protected Target()

public static void Register<T>(string name) where T : Target

Obsolete and replaced by Setup with NLog v5.2. Register a custom Target.

public static void Register(string name, Type targetType)

Obsolete and replaced by Setup with NLog v5.2. Register a custom Target.

protected virtual void CloseTarget()

Closes the target to release any initialized resources

public void Dispose()

Closes the target.

protected virtual void Dispose(bool disposing)

Releases unmanaged and - optionally - managed resources.

public void Flush(AsyncContinuation asyncContinuation)

Flush any pending log messages (in case of asynchronous targets).

protected virtual void FlushAsync(AsyncContinuation asyncContinuation)

Flush any pending log messages

protected virtual void InitializeTarget()

Initializes the target before writing starts

protected void MergeEventProperties(LogEventInfo logEvent)

Merges (copies) the event context properties from any event info object stored in parameters of the given event info object.

Calls the Precalculate on each volatile layout used by this target. This method won't prerender if all layouts in this target are thread-agnostic.

protected string RenderLogEvent(Layout layout, LogEventInfo logEvent)

Renders the logevent into a string-result using the provided layout

protected T RenderLogEvent<T>(Layout<T> layout, LogEventInfo logEvent, T defaultValue = null)

Renders the logevent into a result-value by using the provided layout

protected T ResolveService<T>()

Resolve from DI ServiceRepository

protected virtual void Write(LogEventInfo logEvent)

Writes logging event to the target destination

protected virtual void Write(AsyncLogEventInfo logEvent)

Writes async log event to the log target.

protected virtual void Write(IList<AsyncLogEventInfo> logEvents)

Writes an array of logging events to the log target. By default it iterates on all events and passes them to "Write" method. Inheriting classes can use this method to optimize batch writes.

public void WriteAsyncLogEvent(AsyncLogEventInfo logEvent)

Writes the log to the target.

public void WriteAsyncLogEvents(AsyncLogEventInfo[] logEvents)

Writes the array of log events.

Writes the array of log events.

protected virtual void WriteAsyncThreadSafe(AsyncLogEventInfo logEvent)

Writes a log event to the log target, in a thread safe manner. Any override of this method has to provide their own synchronization mechanism. !WARNING! Custom targets should only override this method if able to provide their own synchronization mechanism. Layout-objects are not guaranteed to be thread-safe, so using them without a SyncRoot-object can be dangerous.

protected virtual void WriteAsyncThreadSafe(IList<AsyncLogEventInfo> logEvents)

Writes an array of logging events to the log target, in a thread safe manner. Any override of this method has to provide their own synchronization mechanism. !WARNING! Custom targets should only override this method if able to provide their own synchronization mechanism. Layout-objects are not guaranteed to be thread-safe, so using them without a SyncRoot-object can be dangerous.

protected virtual void WriteFailedNotInitialized(AsyncLogEventInfo logEvent, Exception initializeException)

LogEvent is written to target, but target failed to successfully initialize