public void CanUseLoggingHandlerWithXmlExceptionFormatter() { MockTraceListener.Reset(); Exception exception = new Exception("test exception"); Guid testGuid = Guid.NewGuid(); LoggingExceptionHandler handler = new LoggingExceptionHandler( "TestCat", 0, TraceEventType.Warning, "test", 10, typeof(XmlExceptionFormatter), Logger.Writer); handler.HandleException(exception, testGuid); Assert.AreEqual(1, MockTraceListener.Entries.Count); XmlDocument doc = new XmlDocument(); doc.LoadXml(MockTraceListener.Entries[0].Message); XmlNode element = doc.DocumentElement.SelectSingleNode("/Exception/@handlingInstanceId"); Assert.IsNotNull(element); Assert.AreEqual(testGuid.ToString("D", CultureInfo.InvariantCulture), element.InnerText); }
/// <summary> /// Logs exceptions encountered by the ClearView application. /// </summary> /// <param name="exception"></param> protected string LogException(Exception exception) { // Add information about the current web request AddExceptionInformation(exception); // Create GUID for this exception (for tracking purposes) System.Guid exceptionGUID = System.Guid.NewGuid(); // Log error LoggingExceptionHandler loggingExceptionHandler = new LoggingExceptionHandler(); loggingExceptionHandler.HandleException(exception, exceptionGUID); // Email error string dsn = ConfigurationManager.ConnectionStrings[ConfigurationManager.AppSettings["DSN"]].ConnectionString; int intEnvironment = Int32.Parse(ConfigurationManager.AppSettings["Environment"]); Variables variables = new Variables(intEnvironment); Functions oFunction = new Functions(0, dsn, intEnvironment); string strEMailIdsTO = oFunction.GetGetEmailAlertsEmailIds("EMAILGRP_DEVELOPER_ERROR"); MessageExceptionHandler messageExceptionHandler = new MessageExceptionHandler(variables.FromEmail(), strEMailIdsTO, variables.SmtpServer()); messageExceptionHandler.HandleException(exception, exceptionGUID); if (intEnvironment == (int)CurrentEnvironment.CORPDMN || intEnvironment == (int)CurrentEnvironment.PNCNT_PROD) { messageExceptionHandler.Email(); } return(messageExceptionHandler.Message); }
public void LoggingHandlerCreatesFormatterWithTheDocumentedConstructor() { MockTraceListener.Reset(); ConstructorSensingExceptionFormatter.Instances.Clear(); Exception exception = new Exception("test exception"); Guid testGuid = Guid.NewGuid(); LoggingExceptionHandler handler = new LoggingExceptionHandler( "TestCat", 0, TraceEventType.Warning, "test", 0, typeof(ConstructorSensingExceptionFormatter), Logger.Writer); handler.HandleException(exception, testGuid); Assert.AreEqual(1, ConstructorSensingExceptionFormatter.Instances.Count); Assert.AreSame(exception, ConstructorSensingExceptionFormatter.Instances[0].Exception); Assert.AreEqual(testGuid, ConstructorSensingExceptionFormatter.Instances[0].HandlingInstanceId); }