Exemplo n.º 1
0
        private Event GetEvent(LogEventInfo logEventInfo)
        {
            var eventCategory = EventCategory?.Render(logEventInfo);
            var eventSeverity = EventSeverity?.Render(logEventInfo);

            var evnt = new Event
            {
                Created  = logEventInfo.TimeStamp,
                Category = !string.IsNullOrEmpty(eventCategory) ? new[] { eventCategory } : null,
                Action   = EventAction?.Render(logEventInfo),
                Id       = EventId?.Render(logEventInfo),
                Kind     = EventKind?.Render(logEventInfo),
                Severity = !string.IsNullOrEmpty(eventSeverity)
                                        ? long.Parse(eventSeverity)
                                        : GetSysLogSeverity(logEventInfo.Level),
                Timezone = TimeZoneInfo.Local.StandardName
            };

            return(evnt);
        }
Exemplo n.º 2
0
        /// <summary>
        ///     Writes the specified logging event to the event log.
        /// </summary>
        /// <param name="logEvent">The logging event.</param>
        protected override void Write(LogEventInfo logEvent)
        {
            var message = Layout.Render(logEvent);

            if (message.Length > 16384)
            {
                // limitation of EventLog API
                message = message.Substring(0, 16384);
            }

            EventLogEntryType entryType;

            if (logEvent.Level >= LogLevel.Error)
            {
                entryType = EventLogEntryType.Error;
            }
            else if (logEvent.Level >= LogLevel.Warn)
            {
                entryType = EventLogEntryType.Warning;
            }
            else
            {
                entryType = EventLogEntryType.Information;
            }

            var eventId = 0;

            if (EventId != null)
            {
                eventId = Convert.ToInt32(EventId.Render(logEvent), CultureInfo.InvariantCulture);
            }

            short category = 0;

            if (Category != null)
            {
                category = Convert.ToInt16(Category.Render(logEvent), CultureInfo.InvariantCulture);
            }

            EventLog.WriteEntry(Source, message, entryType, eventId, category);
        }