// TODO: headers public LogScope Scope(string name, HttpRequestHeaders headers) { var scope = new LogScope(this.type.Name + ">" + name, Thread.CurrentThread.ManagedThreadId); scope.Origin = headers?.Referrer?.ToString() + " [" + string.Join(";", headers?.UserAgent) + "]"; this.BeginStopwatch(scope, name); scope.OnDispose = () => { this.EndStopwatch(scope, name); }; return(scope); }
private void BeginStopwatch(LogScope scope, string process) { lock (_watches) { _watches[process + "~" + Thread.CurrentThread.ManagedThreadId] = new System.Diagnostics.Stopwatch(); _watches[process + "~" + Thread.CurrentThread.ManagedThreadId].Start(); } lock (_scopes) { _scopes.Add(scope); } this.Info(scope, $"{process} has started..."); }
public void EndStopwatch(LogScope scope, string process) { var name = process + "~" + Thread.CurrentThread.ManagedThreadId; if (_watches.ContainsKey(name)) { var watch = _watches[process + "~" + Thread.CurrentThread.ManagedThreadId]; watch.Stop(); this.Info(scope, $"{process} has completed [{watch.Elapsed}].", watch); lock (_watches) { _watches.Remove(process + "~" + Thread.CurrentThread.ManagedThreadId); } lock (_scopes) { _scopes.RemoveAll(f => f.Id == scope.Id); } } }
public LogScope Scope(string name) { var scope = new LogScope(this.type.Name + ">" + name, Thread.CurrentThread.ManagedThreadId); lock (_scopes) { var origin = _scopes.FirstOrDefault(f => f.ThreadId == scope.ThreadId && !string.IsNullOrEmpty(f.Origin)); scope.Level = _scopes.Count(f => f.ThreadId == scope.ThreadId); if (origin != null) { scope.Origin = origin?.Origin; } } this.BeginStopwatch(scope, name); scope.OnDispose = () => { this.EndStopwatch(scope, name); }; return(scope); }
public void Error(LogScope scope, Exception ex) { LogTracer.Instance.Error?.Invoke(this, scope, "Error in " + scope.Name, ex, null); }
public void Error(LogScope scope, string msg, Exception ex) { LogTracer.Instance.Error?.Invoke(this, scope, msg, ex, null); }
public void Error(LogScope scope, string msg, Exception ex, Stopwatch watch) { LogTracer.Instance.Error?.Invoke(this, scope, msg, ex, watch); }
public void Warn(LogScope scope, string msg, Stopwatch watch) { LogTracer.Instance.Warn?.Invoke(this, scope, msg, watch); }
public void Warn(LogScope scope, string msg) { LogTracer.Instance.Warn?.Invoke(this, scope, msg, null); }
public void Info(LogScope scope, string msg) { LogTracer.Instance.Info?.Invoke(this, scope, msg, null); }