public void EntryIsWrittenWhenXmlLoggerWrites()
        {
            File.Delete(XmlFilePath);

            this.LoadConfig("loggingConfiguration50");

            LogEntry entry = LogEntryFactory.GetLogEntry();

            entry.Categories.Clear();
            entry.Categories.Add("General");

            Logger.Write(entry);

            var logEntryXDocument = LogFileReader.GetEntriesXml(XmlFilePath);

            string eventId = logEntryXDocument.Descendants(
                XName.Get("EventID", @"http://schemas.microsoft.com/2004/06/windows/eventlog/system"))
                             .First().Value;

            Assert.IsNotNull(eventId == entry.EventId.ToString());
        }
Esempio n. 2
0
        public void EntryIsWrittenWithValidXmlWhenInvalidXMLCharactersAreUsedInProperties()
        {
            string xmlFile = "testingTrace-xml.log";

            File.Delete(xmlFile);

            var properties = new Dictionary <string, object>();

            properties.Add("invalid xml chars", @"!@#$%^&*(){}<>\/,./';[]\éàфыдлайцкшфывмьт");

            LogEntry logEntry = new LogEntry("message", "TestValidXML", 1, 1, System.Diagnostics.TraceEventType.Resume, "title", properties);

            this.writer.Write(logEntry);

            Assert.IsTrue(File.Exists(xmlFile));
            Assert.AreNotEqual(0, new FileInfo(xmlFile).Length);

            XDocument xmlDocument = LogFileReader.GetEntriesXml(xmlFile);

            Assert.IsTrue(xmlDocument.Nodes().Count() > 0);
        }