Пример #1
0
        // 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);
        }
Пример #2
0
 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...");
 }
Пример #3
0
        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);
                }
            }
        }
Пример #4
0
        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);
        }
Пример #5
0
 public void Error(LogScope scope, Exception ex)
 {
     LogTracer.Instance.Error?.Invoke(this, scope, "Error in " + scope.Name, ex, null);
 }
Пример #6
0
 public void Error(LogScope scope, string msg, Exception ex)
 {
     LogTracer.Instance.Error?.Invoke(this, scope, msg, ex, null);
 }
Пример #7
0
 public void Error(LogScope scope, string msg, Exception ex, Stopwatch watch)
 {
     LogTracer.Instance.Error?.Invoke(this, scope, msg, ex, watch);
 }
Пример #8
0
 public void Warn(LogScope scope, string msg, Stopwatch watch)
 {
     LogTracer.Instance.Warn?.Invoke(this, scope, msg, watch);
 }
Пример #9
0
 public void Warn(LogScope scope, string msg)
 {
     LogTracer.Instance.Warn?.Invoke(this, scope, msg, null);
 }
Пример #10
0
 public void Info(LogScope scope, string msg)
 {
     LogTracer.Instance.Info?.Invoke(this, scope, msg, null);
 }