public override void OnException(System.Web.Mvc.ExceptionContext filterContext) { if (filterContext != null && filterContext.HttpContext != null && filterContext.Exception != null) { //If customError is Off, then AI HTTPModule will report the exception if (filterContext.HttpContext.IsCustomErrorEnabled) { var ai = new CloudWatchLogger(); ai.LogError(filterContext.Exception, "AiHandleErrorAttribute"); } } base.OnException(filterContext); }
static void Main(string[] args) { var client = new AmazonCloudWatchLogsClient(); var logger = new ConsoleLogger() + new TextFileLogger(@"C:\Temp\Logs\1.log") + new TextFileLogger(new DirectoryInfo(@"C:\Temp\Logs\Test")) + CloudWatchLogger.AppendStream(client, "Test", "Test"); var watch = new Stopwatch(); watch.Restart(); for (int i = 0; i < 10000; i++) { logger.LogInfo("Hello World!"); logger.LogInfo("Hello World!"); logger.LogWarning("Multiline\r\nLogs\r\n"); logger.LogError("This has an error!"); logger.LogError("This has an error!"); logger.LogError("This has an error!"); try { throw new Exception("Test exception!"); } catch (Exception e) { logger.LogException(e); } } watch.Stop(); Console.WriteLine(watch.Elapsed); TextLogFileManager.AutoFlush = false; watch.Restart(); for (int i = 0; i < 10000; i++) { logger.LogInfo("Hello World!"); logger.LogInfo("Hello World!"); logger.LogWarning("Multiline\r\nLogs\r\n"); logger.LogError("This has an error!"); logger.LogError("This has an error!"); logger.LogError("This has an error!"); try { throw new Exception("Test exception!"); } catch (Exception e) { logger.LogException(e); } } TextLogFileManager.Flush(); watch.Stop(); Console.WriteLine(watch.Elapsed); Console.ReadLine(); }