/// <summary> /// Application_Error /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Application_Error(object sender, EventArgs e) { try { Exception lastException = Server.GetLastError(); if (lastException == null) { return; } Exception baseException = lastException.GetBaseException(); if (baseException == null) { return; } // 记录异常日志 XYHLogOperator.WriteLog("全局异常捕获", baseException); if (baseException is HttpRequestValidationException) { Response.Write("请不要攻击我,我很脆弱的!!!"); } } finally { if (System.Configuration.ConfigurationManager.AppSettings["ShowErrorOnPage"] == null) { Server.ClearError(); } } }
public IEnumerable <WeatherForecast> Get1() { for (int i = 0; i < 10; i++) { XYHLogOperator.WriteLog("新增一条功能模块记录", "ModuleService/AddOneModule", "dsdsdjsdhskh", "ddsds", LogLevel.Info); XYHLogOperator.WriteLog("新增一条功能模块记录,系统异常", "ModuleService/AddOneModule", "dsdsdjsdhskh", "ddsds", LogLevel.Error); XYHLogOperator.WriteLog(new LogMessage() { MethodName = "1", MethodParam = "11", MethodResult = "111", LogProjectName = "1111", ExecuteEndTime = System.DateTime.Now, ExecuteStartTime = System.DateTime.Now.AddMilliseconds(-1), Level = LogLevel.Info, LogContent = "33" }); } var rng = new Random(); return(Enumerable.Range(1, 5).Select(index => new WeatherForecast { Date = DateTime.Now.AddDays(index), TemperatureC = rng.Next(-20, 55), Summary = Summaries[rng.Next(Summaries.Length)] }) .ToArray()); }
/// <summary> /// action执行以后 /// </summary> /// <param name="actionContext"></param> public override void OnActionExecuted(HttpActionExecutedContext actionContext) { try { // 日志等级 为debug LogLevel thisLogLevel = LogLevel.Debug; // 判断是有 debug 日志模板,如果没有,那么直接返回 if (ExtendLogQueue.logTemplateSetList == null || ExtendLogQueue.logTemplateSetList.Count < 1 || !ExtendLogQueue.logTemplateSetList.Exists(x => x.FilterLevelMax >= thisLogLevel && x.FilterLevelMin <= thisLogLevel)) { return; } // 如果整个contro都不记录日志,那么直接返回 //if (actionContext.ActionContext.ActionDescriptor.GetCustomAttributes<XYHAopAttribute>() != null && // actionContext.ActionContext.ActionDescriptor.GetCustomAttributes<XYHAopAttribute>().Count > 0 && // actionContext.ActionContext.ActionDescriptor.GetCustomAttributes<XYHAopAttribute>()[0].ProcessType == ProcessType.None) //{ // return; //} // 如果接口设置了不记录日志,那么直接跳过 if (actionContext.ActionContext.ActionDescriptor.GetCustomAttributes <XYHMethodAttribute>() != null && actionContext.ActionContext.ActionDescriptor.GetCustomAttributes <XYHMethodAttribute>().Count > 0 && actionContext.ActionContext.ActionDescriptor.GetCustomAttributes <XYHMethodAttribute>()[0].ProcessType == ProcessType.None) { return; } // 获取 startTimeStr DateTime startTime = System.DateTime.Now; string startTimeStr = HttpContext.Current.Request.Headers.GetValues("ActionStartTime") == null ? string.Empty : HttpContext.Current.Request.Headers.GetValues("ActionStartTime")[0]; if (!string.IsNullOrEmpty(startTimeStr)) { startTime = TicksToDate(startTimeStr); } // 返回信息 var objectContent = actionContext.Response.Content as ObjectContent; var returnValue = objectContent.Value; XYHLogOperator.WriteLog(new LogMessage() { MethodName = actionContext.Request.RequestUri.AbsolutePath, MethodParam = actionContext.Request.RequestUri.Query, MethodResult = returnValue.ToString(), LogProjectName = actionContext.Request.RequestUri.AbsoluteUri, ExecuteEndTime = System.DateTime.Now, ExecuteStartTime = startTime, Level = thisLogLevel }); } catch (Exception ex) { } }
public ActionResult Index() { object message = "一个参数日志记录单元测试"; // TODO: 初始化为适当的值 XYHLogOperator.WriteLog(message); Class2 calssAdd = new Class2(); //calssAdd calssAdd = new calssAdd(); calssAdd.SubNum(1, 22); calssAdd.AddNum(1, 11); return(View()); }