public void Setup() { FlatFileSinkData sinkParams = new FlatFileSinkData(); sinkParams.FileName = CommonUtil.FileName; sinkParams.Header = ""; sinkParams.Footer = ""; this.sink = new FlatFileSink(); sink.Initialize(new TestLogSinkConfigurationView(sinkParams)); CommonUtil.ResetEventLogCounter(); }
public void LogMessageToFlatFileWithNullFileName() { FlatFileSinkData sinkParams = new FlatFileSinkData(); sinkParams.FileName = null; this.sink = new FlatFileSink(); sink.Initialize(new TestLogSinkConfigurationView(sinkParams)); CommonUtil.SendTestMessage(this.sink); Assert.AreEqual(1, CommonUtil.EventLogEntryCount(), "confirm warning written to event log"); string entry = CommonUtil.GetLastEventLogEntry(); string expected = SR.DefaultLogDestinationMessage + Environment.NewLine + Environment.NewLine + SR.FileSinkMissingConfiguration; Assert.IsTrue(entry.IndexOf(expected) > -1, "confirm error message"); }
public void MissingRequiredParameters() { // create a flatfile sink without the required parameters FlatFileSink badSink = new FlatFileSink(); badSink.Initialize(new TestLogSinkConfigurationView(new FlatFileSinkData())); CommonUtil.SendTestMessage(badSink); Assert.AreEqual(1, CommonUtil.EventLogEntryCount(), "confirm an error message was written to event log"); string entry = CommonUtil.GetLastEventLogEntry(); string expected = SR.DefaultLogDestinationMessage + Environment.NewLine + Environment.NewLine + SR.FileSinkMissingConfiguration; Assert.IsTrue(entry.IndexOf(expected) > -1, "confirm error message"); expected = CommonUtil.FormattedMessage; Assert.IsTrue(entry.IndexOf(expected) > -1, "confirm message is inside"); }
public void LogMessageToFlatFileWithNoPath() { string fileName = "trace.log"; FlatFileSinkData sinkParams = new FlatFileSinkData(); sinkParams.FileName = fileName; sinkParams.Header = ""; sinkParams.Footer = ""; this.sink = new FlatFileSink(); sink.Initialize(new TestLogSinkConfigurationView(sinkParams)); CommonUtil.SendTestMessage(this.sink); FileStream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read); StreamReader reader = new StreamReader(stream); string contents = reader.ReadToEnd(); stream.Close(); Assert.AreEqual(0, CommonUtil.EventLogEntryCount(), "confirm no messages written to event log"); Assert.IsTrue(contents.IndexOf(CommonUtil.FormattedMessage) > -1, "confirm message is part of contents"); }
public void LogMessageToFlatFileWithNullHeaderFooter() { string fileName = "trace.log"; FlatFileSinkData sinkParams = new FlatFileSinkData(); sinkParams.FileName = fileName; sinkParams.Header = null; sinkParams.Footer = null; this.sink = new FlatFileSink(); sink.Initialize(new TestLogSinkConfigurationView(sinkParams)); CommonUtil.SendTestMessage(this.sink); FileStream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read); StreamReader reader = new StreamReader(stream); string contents = reader.ReadToEnd(); stream.Close(); Assert.AreEqual(0, CommonUtil.EventLogEntryCount(), "confirm no messages written to event log"); Assert.IsTrue(contents.IndexOf(CommonUtil.FormattedMessage) > -1, "confirm message is part of contents"); }