src/NLog/Targets/EventLogTarget.cs
/// <summary>
/// Writes the specified logging event to the event log.
/// </summary>
/// <param name="logEvent">The logging event.</param>
Writes the specified logging event to the event log.
Writes the specified logging event to the event log .
protected override void Write(LogEventInfo logEvent)
        {
            string message = RenderLogEvent(Layout, logEvent);
            EventLogEntryType entryType = GetEntryType(logEvent);
            int eventId = 0;
            string renderEventId = RenderLogEvent(EventId, logEvent);
            if (!string.IsNullOrEmpty(renderEventId) && !int.TryParse(renderEventId, out eventId))
            {
                InternalLogger.Warn("EventLogTarget(Name={0}): WriteEntry failed to parse EventId={1}", Name, renderEventId);
            }
            short category = 0;
            string renderCategory = RenderLogEvent(Category, logEvent);
            if (!string.IsNullOrEmpty(renderCategory) && !short.TryParse(renderCategory, out category))
            {
                InternalLogger.Warn("EventLogTarget(Name={0}): WriteEntry failed to parse Category={1}", Name, renderCategory);
            }
            if (message.Length > MaxMessageLength)
            {
                if (OnOverflow == EventLogTargetOverflowAction.Truncate)
                {
                    message = message.Substring(0, MaxMessageLength);
                    WriteEntry(logEvent, message, entryType, eventId, category);
                }
                else if (OnOverflow == EventLogTargetOverflowAction.Split)
                {
                    for (int offset = 0; offset < message.Length; offset += MaxMessageLength)
                    {
                        string chunk = message.Substring(offset, Math.Min(MaxMessageLength, (message.Length - offset)));
                        WriteEntry(logEvent, chunk, entryType, eventId, category);
                    }
                }
                else if (OnOverflow == EventLogTargetOverflowAction.Discard)
                {
                }
            }
            else
            {
                WriteEntry(logEvent, message, entryType, eventId, category);
            }
        }
protected override void Write ( LogEventInfo logEvent ) { string message = RenderLogEvent ( Layout , logEvent ) ; EventLogEntryType entryType = GetEntryType ( logEvent ) ; int eventId = 0 ; string renderEventId = RenderLogEvent ( EventId , logEvent ) ; if ( ! string . IsNullOrEmpty ( renderEventId ) && ! int . TryParse ( renderEventId , out eventId ) ) { InternalLogger . Warn ( " " , Name , renderEventId ) ; } short category = 0 ; string renderCategory = RenderLogEvent ( Category , logEvent ) ; if ( ! string . IsNullOrEmpty ( renderCategory ) && ! short . TryParse ( renderCategory , out category ) ) { InternalLogger . Warn ( " " , Name , renderCategory ) ; } if ( message . Length > MaxMessageLength ) { if ( OnOverflow == EventLogTargetOverflowAction . Truncate ) { message = message . Substring ( 0 , MaxMessageLength ) ; WriteEntry ( logEvent , message , entryType , eventId , category ) ; } else if ( OnOverflow == EventLogTargetOverflowAction . Split ) { for ( int offset = 0 ; offset < message . Length ; offset += MaxMessageLength ) { string chunk = message . Substring ( offset , Math . Min ( MaxMessageLength , ( message . Length - offset ) ) ) ; WriteEntry ( logEvent , chunk , entryType , eventId , category ) ; } } else if ( OnOverflow == EventLogTargetOverflowAction . Discard ) { } } else { WriteEntry ( logEvent , message , entryType , eventId , category ) ; } }
Writes the specified logging event to the event log.
Writes the specified logging event to the event log .
// limitation of EventLog API // message should not be written
logEvent
LogEventInfo
The logging event.
The logging event .