public override void OnException(MethodExecutionArgs args) { //Suppress the current transaction to ensure exception is not rolled back using (var s = new TransactionScope(TransactionScopeOption.Suppress)) { //Log exception using (var exceptionLogContext = new ExceptionLogContext()) { exceptionLogContext.Set <ExceptionLogEntry>().Add(new ExceptionLogEntry(args.Exception)); exceptionLogContext.SaveChanges(); } } }
private void LogException(System.Exception exception, RouteData routeData) { String controller = routeData.Values["controller"] as String; String action = routeData.Values["action"] as String; ExceptionLogContext context = new ExceptionLogContext(exception) { Level = LogLevel.Error, RequestUrl = HttpContext.Request.RawUrl, RefererUrl = (HttpContext.Request.UrlReferrer != null ? HttpContext.Request.UrlReferrer.ToString() : "null"), Controller = controller, Action = action, Username = JudgeStatusManager.JudgeUserName, UserIP = this.Request.GetRemoteClientIPv4(), UserAgent = HttpContext.Request.UserAgent, TimeStamp = DateTime.Now, }; LogManager.LogException(context); }
public WeatherForecastController(ILogger <WeatherForecastController> logger, ExceptionLogContext exceptionLogContext) { _logger = logger; _exceptionLogContext = exceptionLogContext; }