private LogWriter CreateEventLogWriter() { // This is our message template for any Sink you add below in our case the Windows Event Log TextFormatter formatter = new TextFormatter("Timestamp: {timestamp}{newline}" + "Message: {message}{newline}" + "Category: {category}{newline}" + "Priority: {priority}{newline}" + "Severity: {severity}{newline}" + "Title:{title}{newline}" + "Application Domain: {appDomain}{newline} " + "Process Id: {processId}{newline}" + "Process Name: {processName}{newline}" + "Win32 Thread Id: {win32ThreadId}{newline}" + "Thread Name: {threadName}{newline}" + "Extended Properties: {dictionary({key} - {value})}{newline}"); LogSource emptyTraceSource = new LogSource("none"); LogSource errorsTraceSource = new LogSource(CONS_ERROR_CATEGORY, System.Diagnostics.SourceLevels.All); // Create for all Errors a Listener which writes the messages to the Windows Event Log // with the Event Log Source Property "Code Source". The message format is specified by // the TextFormatter which is in our case the template above. if (!EventLog.SourceExists(LoggingConstants.CONS_LOG_SOURCE)) { EventLog.CreateEventSource(LoggingConstants.CONS_LOG_SOURCE, LoggingConstants.CONS_LOG_NAME); } EventLog eventLog = new EventLog(); eventLog.Source = LoggingConstants.CONS_LOG_SOURCE; eventLog.Log = LoggingConstants.CONS_LOG_NAME; errorsTraceSource.Listeners.Add(new FormattedEventLogTraceListener(eventLog, formatter)); IDictionary <string, LogSource> traceSources = new Dictionary <string, LogSource>(); // Add to Category "Error" our EventLog Listener with the corresponding category in it. traceSources.Add(errorsTraceSource.Name, errorsTraceSource); return(new LogWriter(new ILogFilter[0], // ICollection<ILogFilter> filters traceSources, // IDictionary<string, LogSource> traceSources emptyTraceSource, // LogSource allEventsTraceSource emptyTraceSource, // LogSource notProcessedTraceSource errorsTraceSource, // LogSource errorsTraceSource CONS_ERROR_CATEGORY, // string defaultCategory false, // bool tracingEnabled true)); // bool logWarningsWhenNoCategoriesMatch }
public LogWriter(ILogFilter[] logFilter, IDictionary <string, LogSource> traceSources, LogSource emptyTraceSource1, LogSource emptyTraceSource2, LogSource errorsTraceSource, string cONS_ERROR_CATEGORY, bool v1, bool v2) { this.logFilter = logFilter; this.traceSources = traceSources; this.emptyTraceSource1 = emptyTraceSource1; this.emptyTraceSource2 = emptyTraceSource2; this.errorsTraceSource = errorsTraceSource; this.cONS_ERROR_CATEGORY = cONS_ERROR_CATEGORY; this.v1 = v1; this.v2 = v2; }