Click or drag to resize

TargetWithContext Class

Represents target that supports context capture of ScopeContext Properties + Nested-states
Inheritance Hierarchy

Namespace:  NLog.Targets
Assembly:  NLog (in NLog.dll) Version: 5.3.4+73d83d3161d31288ca5c554cc50d27b6bed5f28b
Syntax
public abstract class TargetWithContext : TargetWithLayout

The TargetWithContext type exposes the following members.

Constructors
  NameDescription
Protected methodTargetWithContext
Constructor
Top
Properties
  NameDescription
Public propertyContextProperties
Gets the array of custom attributes to be passed into the logevent context
Public propertyExcludeProperties
List of property names to exclude when IncludeEventProperties is true
Public propertyIncludeCallSite
Gets or sets a value indicating whether to include call site (class and method name) in the LogEventInfo
Public propertyIncludeCallSiteStackTrace
Gets or sets a value indicating whether to include source info (file name and line number) in the LogEventInfo
Public propertyIncludeEventProperties
Gets or sets the option to include all properties from the log events
Public propertyIncludeGdc
Gets or sets a value indicating whether to include contents of the GlobalDiagnosticsContext dictionary
Public propertyIncludeScopeNested
Gets or sets whether to include the contents of the ScopeContext nested-state-stack.
Public propertyIncludeScopeProperties
Gets or sets whether to include the contents of the ScopeContext properties-dictionary.
Protected propertyIsInitialized
Gets a value indicating whether the target has been initialized.
(Inherited from Target.)
Public propertyLayout
Gets or sets the layout used to format log messages.
(Overrides TargetWithLayoutLayout.)
Protected propertyLoggingConfiguration
Gets the logging configuration this target is part of.
(Inherited from Target.)
Public propertyName
Gets or sets the name of the target.
(Inherited from Target.)
Protected propertySyncRoot
Gets the object which can be used to synchronize asynchronous operations that must rely on the .
(Inherited from Target.)
Top
Methods
  NameDescription
Protected methodCaptureContextGdc
Takes snapshot of GlobalDiagnosticsContext for the LogEventInfo
Protected methodCaptureScopeContextNested
Takes snapshot of nested states from ScopeContext for the LogEventInfo
Protected methodCaptureScopeContextProperties
Takes snapshot of ScopeContext dictionary for the LogEventInfo
Protected methodCloseTarget
Closes the target to release any initialized resources
(Inherited from Target.)
Public methodDispose
Closes the target.
(Inherited from Target.)
Protected methodDispose(Boolean)
Releases unmanaged and - optionally - managed resources.
(Inherited from Target.)
Public methodFlush
Flush any pending log messages (in case of asynchronous targets).
(Inherited from Target.)
Protected methodFlushAsync
Flush any pending log messages
(Inherited from Target.)
Protected methodGenerateUniqueItemName
Generates a new unique name, when duplicate names are detected
Protected methodGetAllProperties(LogEventInfo)
Creates combined dictionary of all configured properties for logEvent
Protected methodGetAllProperties(LogEventInfo, IDictionaryString, Object)
Creates combined dictionary of all configured properties for logEvent
Protected methodGetContextProperties(LogEventInfo)
Checks if any context properties, and if any returns them as a single dictionary
Protected methodGetContextProperties(LogEventInfo, IDictionaryString, Object)
Checks if any context properties, and if any returns them as a single dictionary
Protected methodGetScopeContextNested
Returns the captured snapshot of nested states from ScopeContext for the LogEventInfo
Protected methodGetScopeContextProperties
Returns the captured snapshot of ScopeContext dictionary for the LogEventInfo
Protected methodInitializeTarget
Initializes the target before writing starts
(Inherited from Target.)
Public methodPrecalculateVolatileLayouts
Calls the Precalculate(LogEventInfo) on each volatile layout used by this target. This method won't prerender if all layouts in this target are thread-agnostic.
(Inherited from Target.)
Protected methodRenderLogEvent(Layout, LogEventInfo)
Renders the logevent into a string-result using the provided layout
(Inherited from Target.)
Protected methodRenderLogEventT(LayoutT, LogEventInfo, T)
Renders the logevent into a result-value by using the provided layout
(Inherited from Target.)
Protected methodResolveServiceT
Resolve from DI ServiceRepository
(Inherited from Target.)
Protected methodSerializeItemValue
Take snapshot of a single object value
Protected methodSerializeScopeContextNestedState
Take snapshot of a single object value from ScopeContext nested states
Protected methodSerializeScopeContextProperty
Take snapshot of a single object value from ScopeContext dictionary
Protected methodShouldIncludeProperties
Check if logevent has properties (or context properties)
Public methodToString
Returns a string that represents the current object.
(Inherited from Target.)
Protected methodWrite(AsyncLogEventInfo)
Writes async log event to the log target.
(Inherited from Target.)
Protected methodWrite(IListAsyncLogEventInfo)
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.
(Inherited from Target.)
Protected methodWrite(LogEventInfo)
Writes logging event to the target destination
(Inherited from Target.)
Public methodWriteAsyncLogEvent
Writes the log to the target.
(Inherited from Target.)
Public methodWriteAsyncLogEvents(AsyncLogEventInfo)
Writes the array of log events.
(Inherited from Target.)
Public methodWriteAsyncLogEvents(IListAsyncLogEventInfo)
Writes the array of log events.
(Inherited from Target.)
Protected methodWriteAsyncThreadSafe(AsyncLogEventInfo)
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.
(Inherited from Target.)
Protected methodWriteAsyncThreadSafe(IListAsyncLogEventInfo)
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.
(Inherited from Target.)
Protected methodWriteFailedNotInitialized
LogEvent is written to target, but target failed to successfully initialize
(Inherited from Target.)
Top
Remarks
Examples
 1[Target("MyFirst")]
 2public sealed class MyFirstTarget : TargetWithContext
 3{
 4   public MyFirstTarget()
 5   {
 6       this.Host = "localhost";
 7   }
 8
 9   [RequiredParameter]
10   public Layout Host { get; set; }
11
12   protected override void Write(LogEventInfo logEvent)
13   {
14       string logMessage = this.RenderLogEvent(this.Layout, logEvent);
15       string hostName = this.RenderLogEvent(this.Host, logEvent);
16       return SendTheMessageToRemoteHost(hostName, logMessage);
17   }
18
19   private void SendTheMessageToRemoteHost(string hostName, string message)
20   {
21       // To be implemented
22   }
23}
See Also