Пример #1
0
        /// <summary>
        /// 写入API监控日志
        /// </summary>
        /// <param name="context">请求上下文</param>
        /// <param name="timeTotal">请求耗时</param>
        /// <param name="exception">异常</param>
        /// <param name="exceptionResponse">发生异常时响应</param>
        public static void WriteApiMonitorLog(HttpContext context, string responseMsg, long timeTotal, string exception = null, string exceptionResponse = null)
        {
            LogMonitorDto monitorDto = new LogMonitorDto(context)
            {
                BeginTime  = DateTime.Now.AddMilliseconds(timeTotal),
                TimeTotal  = timeTotal,
                ModuleType = ModuleType.api_dotnet,
                ApiUrl     = context.Request.Path,
                Arguments  = context.GetClientPostData(),
                Level      = LogLevel.Info
            };

            if (!exception.IsNullOrEmpty())
            {
                monitorDto.Exception = exception;
                monitorDto.Level     = LogLevel.Error;
                if (exceptionResponse.IsNullOrEmpty())
                {
                    monitorDto.Message = exception;
                }
                else
                {
                    monitorDto.Message = exceptionResponse;
                }
            }
            else
            {
                monitorDto.Message = responseMsg;
            }

            Task.Factory.StartNew(() =>
            {
                //TryLogMonitor(monitorDto);
            });
        }
Пример #2
0
 public static void TryLogMonitor(LogMonitorDto dto)
 {
     TryLog(dto, LogType.Db, "", dto.Level, sendMail: dto.Level == LogLevel.Error);
 }