public void FlatFileSinkDataTest() { string fileName = "testFlatFileName"; string footer = "testFooter"; string header = "testHeader"; string name = "testName"; string type = typeof(FlatFileSink).AssemblyQualifiedName; FlatFileSinkData data = new FlatFileSinkData(); data.FileName = fileName; data.Footer = footer; data.Header = header; data.Name = name; data.TypeName = type; FlatFileSinkNode node = new FlatFileSinkNode(data); GeneratedApplicationNode.Nodes.Add(node); FlatFileSinkData nodeData = (FlatFileSinkData)node.SinkData; Assert.AreEqual(fileName, nodeData.FileName); Assert.AreEqual(footer, nodeData.Footer); Assert.AreEqual(header, nodeData.Header); Assert.AreEqual(name, nodeData.Name); Assert.AreEqual(type, nodeData.TypeName); }
public void FlatFileSink() { string sinkName = "SampleTextFileSink"; FlatFileSinkData sink = new FlatFileSinkData(); sink.Name = sinkName; SinkFromFactory(sink); }
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 FlatFileSinkDataPropertiesTest() { FlatFileSinkData data = new FlatFileSinkData(); string fileName = "Filename"; string footer = "Footer"; string header = "Header"; data.FileName = fileName; data.Footer = footer; data.Header = header; Assert.AreEqual(fileName, data.FileName); Assert.AreEqual(footer, data.Footer); Assert.AreEqual(header, data.Header); }
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 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"); }
private void WriteMessageToFile(LogEntry logEntry) { FlatFileSinkData flatFileSinkData = GetFlatFileSinkDataFromCursor(); string directory = Path.GetDirectoryName(flatFileSinkData.FileName); if (directory.Length == 0) { directory = AppDomain.CurrentDomain.BaseDirectory; } if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } using (FileStream fileStream = new FileStream(Path.Combine(directory, flatFileSinkData.FileName), FileMode.Append, FileAccess.Write, FileShare.ReadWrite)) { using (StreamWriter writer = new StreamWriter(fileStream)) { lock (syncObject) { if (flatFileSinkData.Header.Length > 0) { writer.WriteLine(flatFileSinkData.Header); } writer.WriteLine(FormatEntry(logEntry)); if (flatFileSinkData.Footer.Length > 0) { writer.WriteLine(flatFileSinkData.Footer); } writer.Flush(); } } } }
private bool ValidateParameters(LogEntry logEntry) { FlatFileSinkData flatFileSinkData = GetFlatFileSinkDataFromCursor(); bool valid = true; if (flatFileSinkData.Header == null) { flatFileSinkData.Header = ""; } if (flatFileSinkData.Footer == null) { flatFileSinkData.Footer = ""; } if (flatFileSinkData.FileName == null || flatFileSinkData.FileName.Length == 0) { valid = false; logEntry.AddErrorMessage(SR.FileSinkMissingConfiguration); this.defaultSink.SendMessage(logEntry); } return(valid); }
/// <summary> /// Creates node with specified configuration data. /// </summary> /// <param name="flatFileSinkData">Configuration data.</param> public FlatFileSinkNode(FlatFileSinkData flatFileSinkData) : base(flatFileSinkData) { this.flatFileSinkData = flatFileSinkData; }