예제 #1
0
        /// <summary>
        /// Write the log entry to the configured event log.
        /// </summary>
        /// <param name="logEntry"><see cref="LogEntry"></see> to be logged to event log</param>
        protected override void SendMessageCore(LogEntry logEntry)
        {
            EventLogSinkData eventLogSinkData = GetEventLogSinkDataFromCursor();

            short categoryId = defaultSink.GetCategoryId(logEntry);

            if (ValidateParameters(logEntry))
            {
                try
                {
                    using (EventLog eventLog = new EventLog(eventLogSinkData.EventLogName, ".", eventLogSinkData.EventSourceName))
                    {
                        eventLog.WriteEntry(
                            FormatEntry(logEntry),
                            SeverityMap.GetEventLogEntryType(logEntry.Severity),
                            logEntry.EventId,
                            categoryId);
                    }
                }
                catch (Exception e)
                {
                    logEntry.AddErrorMessage(SR.SinkFailure(e.ToString()));
                    throw;
                }
                catch
                {
                    logEntry.AddErrorMessage(SR.SinkFailure(SR.UnknownError));
                    throw;
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Write the log entry to the configured event log.
        /// </summary>
        /// <param name="logEntry"><see cref="LogEntry"></see> to be written to the event log</param>
        public void SendMessage(LogEntry logEntry)
        {
            try
            {
                short categoryID = GetCategoryId(logEntry);

                logEntry.AddErrorMessage(SR.DefaultLogDestinationMessage);

                TextFormatter formatter = formatter = new TextFormatter(new TextFormatterData());
                string        message   = FormatEntry(formatter, logEntry);


                EventLog.WriteEntry(
                    eventLogSourceName,
                    message,
                    SeverityMap.GetEventLogEntryType(logEntry.Severity),
                    logEntry.EventId,
                    categoryID);

                LoggingLogDeliveryFailureEvent.Fire(message);
            }
            catch (Exception e)
            {
                throw new LoggingException(SR.DefaultLogDestinationFailed, e);
            }
            catch
            {
                throw new LoggingException(SR.DefaultLogDestinationFailed);
            }
        }
예제 #3
0
        /// <summary>
        /// Method used to write exception and additional information to the event log, and clears the
        /// messages collection.
        /// </summary>
        /// <param name="exception">The exception object whose information should be written to log file.</param>
        /// <param name="severity">The type of event log entry (warning, information, error,...)</param>
        public void WriteToLog(Exception exception, Severity severity)
        {
            // Verify that the specified event log exists and is valid to write to.
            CheckEventLog();

            string finalMessage = String.Empty;

            finalMessage = GetMessage(exception);
            additionalInfo.Clear();

            if (severity == Severity.Error || severity == Severity.Warning)
            {
                // this only fires WMI events
                LoggingServiceFailureEvent.Fire(finalMessage, exception);
            }
            EventLog.WriteEntry(this.ApplicationName, finalMessage, SeverityMap.GetEventLogEntryType(severity));
        }