private static void Main(string[] args) { using (var logWriter = CreateStandardOutputLogWriter()) { var shouter = new Shouter(logWriter); while (true) { shouter.Shout(new System.Threading.CancellationToken()); } } }
protected void ShoutLoop() { // Configue a LogWriter to write to the Windows Event Log. var eventLog = new EventLog("Application", ".", "ShoutService"); var eventLogTraceListener = new FormattedEventLogTraceListener(eventLog) { Filter = new SeverityFilter(new TraceEventType[] { TraceEventType.Error, TraceEventType.Information, TraceEventType.Warning}) }; var config = new LoggingConfiguration(); config.AddLogSource("All", SourceLevels.All, true) .AddTraceListener(eventLogTraceListener); // A using statement ensures the log gets flushed when this process exits. using (var logWriter = new LogWriter(config)) { var shouter = new Shouter(logWriter); do { shouter.Shout(cancellationTokenSource.Token); } while (!cancellationTokenSource.Token.IsCancellationRequested); } }