protected virtual void Log(string title, string message, Dictionary <string, string> tags, LogLevel level) { Console.WriteLine(LoggingEnabled); Console.WriteLine(Settings.LoggingEnabled); if (!LoggingEnabled) { return; } LogOnOff onOff = LogOnOffManager.GetLogOnOff(); if (level == LogLevel.Debug && onOff.Debug != 1) { return; } if (level == LogLevel.Info && onOff.Info != 1) { return; } if (level == LogLevel.Warn && onOff.Warn != 1) { return; } if (level == LogLevel.Error && onOff.Error != 1) { return; } LogEntity log = this.CreateLog(Source, title, message, tags, level); block.Enqueue(log); }
public bool GetOnOff(LogLevel level) { if (!LoggingEnabled) { return(false); } LogOnOff onOff = LogOnOffManager.GetLogOnOff(); if (level == LogLevel.Debug && onOff.Debug != 1) { return(false); } if (level == LogLevel.Info && onOff.Info != 1) { return(false); } if (level == LogLevel.Warn && onOff.Warn != 1) { return(false); } if (level == LogLevel.Error && onOff.Error != 1) { return(false); } return(true); }
/// <summary> /// 从服务端获取并刷新日志开关,10分钟缓存 /// </summary> /// <returns></returns> public static void RefreshLogOnOff() { if ((DateTime.Now - LastUpdateTime).TotalMinutes < LogOnOffCacheTimeOut) { return; } string resp = string.Empty; try { using (WebClient _client = new WebClientEx(10 * 1000)) { byte[] resp_byte = _client.DownloadData(GetLogOnOffUrl); resp = Encoding.UTF8.GetString(resp_byte); } } catch { } if (!string.IsNullOrWhiteSpace(resp)) { logOnOff = new LogOnOff(); string[] arr = resp.Split(','); logOnOff.Debug = Convert.ToByte(arr[0]); logOnOff.Info = Convert.ToByte(arr[1]); logOnOff.Warm = Convert.ToByte(arr[2]); logOnOff.Error = Convert.ToByte(arr[3]); } LastUpdateTime = DateTime.Now; }