EventLogTarget Class |
Namespace: NLog.Targets
The EventLogTarget type exposes the following members.
Name | Description | |
---|---|---|
EventLogTarget |
Initializes a new instance of the EventLogTarget class.
| |
EventLogTarget(String) |
Initializes a new instance of the EventLogTarget class.
|
Name | Description | |
---|---|---|
Category |
Gets or sets the layout that renders event Category.
| |
EntryType |
Optional entry type. When not set, or when not convertible to EventLogEntryType then determined by LogLevel | |
EventId |
Gets or sets the layout that renders event ID.
| |
IsInitialized |
Gets a value indicating whether the target has been initialized.
(Inherited from Target.) | |
Layout |
Gets or sets the layout used to format log messages.
(Inherited from TargetWithLayout.) | |
Log |
Gets or sets the name of the Event Log to write to. This can be System, Application or any user-defined name.
| |
LoggingConfiguration |
Gets the logging configuration this target is part of.
(Inherited from Target.) | |
MachineName |
Gets or sets the name of the machine on which Event Log service is running.
| |
MaxKilobytes |
Gets or sets the maximum Event log size in kilobytes.
| |
MaxMessageLength |
Gets or sets the message length limit to write to the Event Log.
| |
Name |
Gets or sets the name of the target.
(Inherited from Target.) | |
OnOverflow |
Gets or sets the action to take if the message is larger than the MaxMessageLength option.
| |
Source |
Gets or sets the value to be used as the event Source.
| |
SyncRoot |
Gets the object which can be used to synchronize asynchronous operations that must rely on the .
(Inherited from Target.) |
Name | Description | |
---|---|---|
CloseTarget |
Closes the target to release any initialized resources
(Inherited from Target.) | |
Dispose |
Closes the target.
(Inherited from Target.) | |
Dispose(Boolean) |
Releases unmanaged and - optionally - managed resources.
(Inherited from Target.) | |
Flush |
Flush any pending log messages (in case of asynchronous targets).
(Inherited from Target.) | |
FlushAsync |
Flush any pending log messages
(Inherited from Target.) | |
InitializeTarget |
Initializes the target before writing starts
(Overrides TargetInitializeTarget.) | |
Install |
Performs installation which requires administrative permissions.
| |
IsInstalled |
Determines whether the item is installed.
| |
PrecalculateVolatileLayouts |
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.) | |
RenderLogEvent(Layout, LogEventInfo) |
Renders the logevent into a string-result using the provided layout
(Inherited from Target.) | |
RenderLogEventT(LayoutT, LogEventInfo, T) |
Renders the logevent into a result-value by using the provided layout
(Inherited from Target.) | |
ResolveServiceT |
Resolve from DI ServiceRepository (Inherited from Target.) | |
ToString | Returns a string that represents the current object. (Inherited from Target.) | |
Uninstall |
Performs uninstallation which requires administrative permissions.
| |
Write(AsyncLogEventInfo) |
Writes async log event to the log target.
(Inherited from Target.) | |
Write(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.) | |
Write(LogEventInfo) |
Writes logging event to the target destination
(Overrides TargetWrite(LogEventInfo).) | |
WriteAsyncLogEvent |
Writes the log to the target.
(Inherited from Target.) | |
WriteAsyncLogEvents(AsyncLogEventInfo) |
Writes the array of log events.
(Inherited from Target.) | |
WriteAsyncLogEvents(IListAsyncLogEventInfo) |
Writes the array of log events.
(Inherited from Target.) | |
WriteAsyncThreadSafe(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.) | |
WriteAsyncThreadSafe(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.) | |
WriteFailedNotInitialized |
LogEvent is written to target, but target failed to successfully initialize
(Inherited from Target.) |
To set up the target in the configuration file, use the following syntax:
1<?xml version="1.0" ?> 2<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" 3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 4 <targets> 5 <target name="eventlog" xsi:type="EventLog" layout="${logger}: ${message}" source="My Source" log="Application" onOverflow="Truncate" /> 6 </targets> 7 8 <rules> 9 <logger name="*" minlevel="Debug" writeTo="eventlog" /> 10 </rules> 11</nlog>
To set up the log target programmatically use code like this:
1using NLog; 2using NLog.Targets; 3using NLog.Win32.Targets; 4 5class Example 6{ 7 static void Main(string[] args) 8 { 9 EventLogTarget target = new EventLogTarget(); 10 target.Source = "My Source"; 11 target.Log = "Application"; 12 target.MachineName = "."; 13 target.Layout = "${logger}: ${message}"; 14 target.OnOverflow = EventLogTargetOverflowAction.Truncate; 15 16 NLog.Config.SimpleConfigurator.ConfigureForTargetLogging(target, LogLevel.Debug); 17 18 Logger logger = LogManager.GetLogger("Example"); 19 logger.Debug("log message"); 20 } 21}