Exemple #1
0
 /// <summary>
 /// Initialises a new instance of the <see cref="TimeTrace"/> class using a specified timer.
 /// </summary>
 /// <param name="timer">Timer to use for measurements.</param>
 /// <exception cref="ArgumentNullException">Thrown when <paramref name="timer"/> is null.</exception>
 public TimeTrace(ITraceTimer timer)
 {
     // Make sure that any exceptions are thrown *before* overwriting any AsyncLocal<T> values.
     _timer         = timer ?? throw new ArgumentNullException(nameof(timer));
     _previous      = _current.Value;
     _current.Value = this;
     _timer.Start();
 }
Exemple #2
0
 /// <summary>
 /// Initialises a new instance of the <see cref="TraceScope"/> class.
 /// </summary>
 /// <param name="trace">Trace that the scope belongs to.</param>
 /// <param name="name">Name of the scope.</param>
 public TraceScope(TimeTrace trace, string name)
 {
     _name    = name;
     _startNs = trace._timer.ElapsedNanoseconds;
     _trace   = trace;
     Parent   = trace._currentScope.Value;
     trace._currentScope.Value = this;
     trace.OnScopeCreated(this);
 }