public void LogTest2() { ////public void Log(string message, int eventId, EventLogEntryType severity, string category) string strMessage = "Custom Message by Automation Test Code.EID>0. " + Guid.NewGuid().ToString("N"); EventLogEntryType Severity = EventLogEntryType.Error; int EID = DateTime.Now.Second; LogModule.Logging.EventLogLogger eLogger = new LogModule.Logging.EventLogLogger(); eLogger.Log(strMessage, EID, EventLogEntryType.Error, ""); bool isValid = LogUtils.ValidateEventLog(strEventSourceName, EID, strMessage, Severity); eLogger = null; Assert.IsTrue(isValid, "Message did not get logged in Eventlog"); }
public void LogTest() { ////public void Log(string message, int eventId, EventLogEntryType severity, string category) //string strMess="Custom message from Nanda"; string strMess = "Custom message from Test Automation"; int EID = new Random().Next(1, 20); LogModule.Logging.EventLogLogger eLogger = new LogModule.Logging.EventLogLogger(); eLogger.Log(strMess, EID, EventLogEntryType.Error, ""); bool isValid = LogUtils.ValidateEventLog(strEventSourceName, EID, strMess); if (isValid) { Assert.IsTrue(true); } else { Assert.Fail("Message did not get logged in Eventlog, but entry is made"); } #region Old Commented Moved to logutils //using (EventLog log = new EventLog("Application", System.Environment.MachineName, strEventSourceName)) //{ // foreach (EventLogEntry entry in log.Entries) // { // if (entry.EntryType == System.Diagnostics.EventLogEntryType.Error) // { // //if (entry.Message == strMess && entry.EventID==5) // if (entry.Source == strEventSourceName) // if (entry.InstanceId == EID) // if (entry.Message == strMess) // Assert.IsTrue(true); // else // Assert.Fail("Message did not get logged in Eventlog, but entry is made"); // } // } //} #endregion }
public void LogTestNegative() { ////public void Log(string message, int eventId, EventLogEntryType severity, string category) // string strMess = "Custom message from Test Automation"; int EID = new Random().Next(1, 20); LogModule.Logging.EventLogLogger eLogger = new LogModule.Logging.EventLogLogger(); eLogger.Log(string.Empty, EID, EventLogEntryType.Warning, null); using (EventLog log = new EventLog("Application", System.Environment.MachineName, strEventSourceName)) { foreach (EventLogEntry entry in log.Entries) { if (entry.EntryType == System.Diagnostics.EventLogEntryType.Error) { //if (entry.Message == strMess && entry.EventID==5) if (entry.Source == strEventSourceName) { if (entry.InstanceId == EID) { if (entry.Message == string.Empty) { Assert.Fail("There was an entry in Eventlog, which is not the expected one"); } else { Assert.IsTrue(true); } } } } } } }