Ejemplo n.º 1
0
        /// <summary>
        /// 实例化IInterceptor唯一方法
        /// </summary>
        /// <param name="invocation">包含被拦截的方法的信息</param>
        public void Intercept(IInvocation invocation)
        {
            //记录被拦截方法的日志信息
            Exception exception = null;
            var       logMsg    = $"{DateTime.Now:yyyyMMddHHmmss}=>当前执行方法:{invocation.TargetType.Name}_{invocation.Method.Name} 参数是:{string.Join(",", invocation.Arguments.Select(m => (m ?? "").ToString()).ToArray())}{Environment.NewLine}";

            try
            {
                invocation.Proceed();
            }
            catch (Exception e)
            {
                exception = e;
                logMsg   += $"方法执行异";
            }
            logMsg += $"方法执行完毕,返回结果:{invocation.ReturnValue}";
            if (exception != null)
            {
                _log.Error(typeof(LogAop), logMsg, exception);
            }
            else
            {
                _log.Debug(typeof(LogAop), logMsg);
            }
        }
Ejemplo n.º 2
0
 public IActionResult LogTest()
 {
     try
     {
         _logger.Error(typeof(TestController), "这是错误日志", new Exception("123"));
         _logger.Debug(typeof(TestController), "这是bug日志");
         return(SuccessMsg());
     }
     catch (Exception err)
     {
         _logger.Error("log日志记录失败!", err.Message);
         return(FailedMsg("log日志记录失败!" + err.Message));
     }
 }
        public IActionResult Get()
        {
            var helper = new MongoDbHelper("EdayingDB", false, true);
            var result = userService.Find(2);


            #region Exceptionless测试

            loggerHelper.Debug("Salary", JsonConvert.SerializeObject(result.Data));
            loggerHelper.Error("Salary", JsonConvert.SerializeObject(result.Data));
            loggerHelper.Info("Salary", JsonConvert.SerializeObject(result.Data));
            loggerHelper.Trace("Salary", JsonConvert.SerializeObject(result.Data));
            loggerHelper.Warn("Salary", JsonConvert.SerializeObject(result.Data));

            #endregion

            Task.Run(() => helper.Insert("User", result.Data));

            return(Json(result));
        }