public void DontWriteHeaderOrFooterWhenEventsAreFiltered() { const string header = "MockHeader"; const string footer = "MockFooter"; const string fileName = "rolling.log"; string filePath = AppDomain.CurrentDomain.BaseDirectory + "\\" + fileName; try { LogEntry log = new LogEntry("Header nor footer written", "Category", 1, 1, TraceEventType.Error, "FilteredEventsDontWriteHeaderNorFooter", null); RollingFlatFileTraceListener listener = new RollingFlatFileTraceListener(filePath, header, footer, null, 100, "mmddyyyy", RollFileExistsBehavior.Overwrite, RollInterval.Day); listener.Filter = new EventTypeFilter(SourceLevels.Off); listener.TraceData(null, "Error", TraceEventType.Error, 1, log); listener.Flush(); listener.Close(); Assert.IsTrue(File.Exists(filePath)); StreamReader reader = new StreamReader(filePath); string content = reader.ReadToEnd(); reader.Close(); Assert.IsFalse(content.Contains(header)); Assert.IsFalse(content.Contains(footer)); } finally { File.Delete(filePath); } }