private void WriteLog(int sniffMask, TracingLevel level, Exception ex, string from, string to, string message) { // NextVersion //int repeat; //if (TracingManager.AntiRepeat && !sniffed) { // if (AntiRepeater.IsRepeated(out repeat)) { // return; // } //} else { // repeat = 1; //} //if (repeat > 1) { // message = string.Format("!!!Repeat {0} times in last 5 seconds\r\n{1}", repeat, message); //} TracingEvent evt = new TracingEvent(); evt.Level = level; evt.LoggerName = _loggerName; evt.Time = DateTime.Now; evt.Message = message; evt.ProcessInfo = ServiceEnvironment.ProcessInfo; evt.ServiceName = ServiceEnvironment.ServiceName; evt.ComputerName = ServiceEnvironment.ComputerName; evt.ThreadInfo = TracingHelper.FormatThreadInfo(Thread.CurrentThread); evt.From = from ?? ""; evt.To = to ?? ""; evt.Error = ex == null ? "" : ex.ToString(); evt.Repeat = 1; // repeat; if (sniffMask > 0) { for (int i = 0; i < TracingSniffer.MaxSniffer; i++) { if ((sniffMask & (1 << i)) > 0) { TracingSniffer sniffer = _sniffers[i]; if (sniffer != null) { sniffer.Enqueue(evt); } } } } if (evt.Level == TracingLevel.Error) { _observerItem.LastError = evt.Message; if (ex != null) { _observerItem.LastException = evt.Error; } } TracingManager.Enqueue(evt); }
public void AddSniffer(TracingSniffer sniffer) { if (_sniffers == null) { _sniffers = new TracingSniffer[TracingSniffer.MaxSniffer]; } for (int i = 0; i < TracingSniffer.MaxSniffer; i++) { if (_sniffers[i] == null) { _sniffers[i] = sniffer; break; } } }
public void RemoveSniffer(TracingSniffer sniffer) { if (_sniffers == null) { return; } for (int i = 0; i < TracingSniffer.MaxSniffer; i++) { if (_sniffers[i] == sniffer) { _sniffers[i] = null; break; } } }
private bool CanLog(TracingLevel level, string from, string to, out int sniffMask) { sniffMask = 0; if (_sniffers != null) { try { for (int i = 0; i < TracingSniffer.MaxSniffer; i++) { TracingSniffer sniffer = _sniffers[i]; if (sniffer != null) { if (sniffer.CanSniff(level, from, to)) { sniffMask |= (1 << i); } } } } catch (Exception ex) { SystemLog.Unexcepted(ex); } } return((level >= TracingManager.Level) || (sniffMask > 0)); }