public void Error(Exception ex, string msg) { logger.Error(ex, msg); if (ThreadSlot.LogicalGetData() != null && ThreadSlot.LogicalGetData().IsDebug) { //记录到表里 logger.Warn(ex, msg); } }
public void Error(string msg, Exception err) { logger.Error(msg, err); if (ThreadSlot.LogicalGetData() != null && ThreadSlot.LogicalGetData().IsDebug) { //记录到表里 logger.Warn(msg, err); } }
public void Error(string msg, params object[] args) { logger.Error(msg, args); if (ThreadSlot.LogicalGetData() != null && ThreadSlot.LogicalGetData().IsDebug) { //记录到表里 logger.Warn(msg, args); } }
public void Warn(string msg) { logger.Warn(msg); if (ThreadSlot.LogicalGetData() != null && ThreadSlot.LogicalGetData().IsDebug) { //记录到表里 logger.Warn(msg); } }
public void Fatal(Exception err, string msg) { logger.Fatal(err, msg); if (ThreadSlot.LogicalGetData() != null && ThreadSlot.LogicalGetData().IsDebug) { //记录到表里 logger.Warn(err, msg); } }
/// <summary> /// 初始化线程本地数据 /// </summary> private static void InitThreadSlot() { //lock ("s") //{ //if (_bagLocal.Value == null || string.IsNullOrEmpty(_bagLocal.Value.TraceId)) //{ ThreadLocalData data = null; //http请求 try { if (HttpContext.Current != null && HttpContext.Current.Request != null && HttpContext.Current.Request.Url != null) { //服务转发过来的请求 data = HttpContext.Current.Request.Headers["BTProcessInfo"] == null ? null : JsonConvert.DeserializeObject <ThreadLocalData>(HttpContext.Current.Request.Headers["BTProcessInfo"]); if (data != null) { //Helper.LogHelper.WriteLog("Server:请求线程数据0000"); data.FromUrl = data.FromUrl; // data.ToUrl = HttpContext.Current.Request.Url.ToSafeString(""); data.TraceSecondId = string.IsNullOrEmpty(ThreadSlot.GetClientID()) ? null : ThreadSlot.GetClientID().Split('|')[0]; data.StartTime = data.StartTime == DateTime.MinValue ? DateTime.Now : data.StartTime; } else { // Helper.LogHelper.WriteLog("Server:请求线程数据1111"); //app终端 请求带有requestToken string requestToken = HttpContext.Current.Request.Headers["traceToken"] == null ? string.Empty : HttpContext.Current.Request.Headers["traceToken"].ToString(); //AccessToken 获取到用户token 判断是不是调试用户 add by weiyz 2019-12-9 string ISDEBUG = HttpContext.Current.Request.Headers.AllKeys.Contains("DEBUGEMP") == false ? string.Empty : HttpContext.Current.Request.Headers["DEBUGEMP"].ToString(); //Helper.LogHelper.WriteLog("Server:请求线程数据2222:" + ISDEBUG); //LogService.Default.Debug(HttpContext.Current.Request.Url.AbsoluteUri + "-traceToken-" + (string.IsNullOrEmpty(requestToken) ? "notoken" : requestToken)); if (data == null && (!string.IsNullOrEmpty(requestToken))) { data = new ThreadLocalData(); data.TraceId = requestToken;//HttpContext.Current.Request.Headers["traceToken"].ToString(); data.FromUrl = GetAppOS(); data.ToUrl = HttpContext.Current.Request.Url.AbsoluteUri; data.StartTime = DateTime.Now; data.TraceSecondId = string.IsNullOrEmpty(ThreadSlot.GetClientID()) ? null : ThreadSlot.GetClientID().Split('|')[0]; data.IsDebug = ISDEBUG == "1"; } } if (data != null) { CallContext.LogicalSetData("tp", data); } //ExecutionContext.RestoreFlow(); } else { data = CallContext.LogicalGetData("tp") == null ? null : CallContext.LogicalGetData("tp") as ThreadLocalData; //ThreadPool.QueueUserWorkItem(p => { object s = CallContext.LogicalGetData("tp"); }); } } catch { data = CallContext.LogicalGetData("tp") == null ? null : CallContext.LogicalGetData("tp") as ThreadLocalData; } _bagLocal.Value = data == null ? new ThreadLocalData() { TraceId = Guid.NewGuid().ToString("N"), StartTime = DateTime.Now, TraceSecondId = string.IsNullOrEmpty(ThreadSlot.GetClientID()) ? null : ThreadSlot.GetClientID().Split('|')[0], FromUrl = GetCurrentWebSiteName() } : data; if (CallContext.LogicalGetData("tp") == null) { CallContext.LogicalSetData("tp", _bagLocal.Value); } //LogService.Default.Debug("clientID=" + _bagLocal.Value.TraceSecondId); //} // } }