public void ShouldRaiseLaunchBeginNewScope() { ILogContext lc = null; ILogScope logScope = null; var listener = new Mock <ICommandsListener>(); listener.Setup(o => o.Initialize(It.IsAny <ICommandsSource>())).Callback <ICommandsSource>(s => { s.OnBeginLogScopeCommand += (a, b) => { lc = a; logScope = b.LogScope; }; }); var extensionManager = new ExtensionManager(); extensionManager.CommandsListeners.Add(listener.Object); var launchContext = new LaunchContext(extensionManager, new CommandsSource(new List <ICommandsListener> { listener.Object })); launchContext.Log.BeginScope("qwe"); lc.Should().Be(launchContext); logScope.Name.Should().Be("qwe"); logScope.Context.Should().Be(launchContext); }
public void ShouldRaiseTestEndScope() { ILogContext tc = null; ILogScope logScope = null; var listener = new Mock <ICommandsListener>(); listener.Setup(o => o.Initialize(It.IsAny <ICommandsSource>())).Callback <ICommandsSource>(s => { s.OnEndLogScopeCommand += (a, b) => { tc = a; logScope = b.LogScope; }; }); var extensionManager = new ExtensionManager(); extensionManager.CommandsListeners.Add(listener.Object); var testContext = new TestContext(extensionManager, new CommandsSource(new List <ICommandsListener> { listener.Object })); var scope = testContext.Log.BeginScope("qwe"); scope.Dispose(); tc.Should().Be(testContext); logScope.Name.Should().Be("qwe"); logScope.EndTime.Should().BeCloseTo(DateTime.UtcNow); }
public static ILogScope WithCorrelationHandle(this ILogScope scope, [NotNull] object correlationHandle) { if (correlationHandle == null) { throw new ArgumentNullException(nameof(correlationHandle)); } return(scope.With(nameof(WithCorrelationHandle), correlationHandle)); }
public void EndScope(ILogScope logScope) { var communicationMessage = new EndScopeCommunicationMessage { Id = logScope.Id, EndTime = logScope.EndTime.Value, Status = logScope.Status }; Console.WriteLine(ModelSerializer.Serialize <EndScopeCommunicationMessage>(communicationMessage)); }
public void ShouldImplicitlySetBeginAndEndTime() { ILogScope scope = Context.Current.Log.BeginScope("q"); scope.BeginTime.Should().BeCloseTo(DateTime.UtcNow); scope.EndTime.Should().BeNull(); scope.Dispose(); scope.EndTime.Should().BeCloseTo(DateTime.UtcNow); }
public void BeginScope(ILogScope logScope) { var communicationMessage = new BeginScopeCommunicationMessage { Id = logScope.Id, ParentScopeId = logScope.Parent?.Id, Name = logScope.Name, BeginTime = logScope.BeginTime }; Console.WriteLine(ModelSerializer.Serialize <BeginScopeCommunicationMessage>(communicationMessage)); }
public LogScope(ILogContext logContext, IExtensionManager extensionManager, CommandsSource commandsSource, ILogScope root, ILogScope parent, string name) : base(logContext, extensionManager, commandsSource) { if (string.IsNullOrEmpty(name)) { throw new ArgumentException("Log scope name cannot be null of empty.", nameof(name)); } Root = root; Parent = parent; Name = name; CommandsSource.RaiseOnBeginScopeCommand(commandsSource, logContext, new LogScopeCommandArgs(this)); }
private async Task <ILogScope> DoSomeWorkAsync(ILogScope expectedRootScope) { await Task.Delay(1); using (var scope = Context.Current.Log.BeginScope("q")) { await Task.Delay(new Random().Next(20)); Context.Current.Log.Root.Should().BeSameAs(expectedRootScope); } return(Context.Current.Log); }
public void OnBefore(string name, ParamInfo[] parameters) { _scope = _parentScope.BeginScope(name); if (parameters != null) { foreach (var paramInfo in parameters) { _scope.Trace($"{paramInfo.Name} `{paramInfo.Value}`"); } } //Console.WriteLine($"Hi from .OnBefore: {_scope.Id} " + name); }
protected void Step(string name, Action action) { using (ILogScope logScope = Context.Current.Log.BeginScope(name)) { try { Assert.DoesNotThrow(action.Invoke); } catch (Exception ex) { logScope.Error(ex.Message); logScope.Status = LogScopeStatus.Failed; throw; } finally { } } }
public bool Handle(ILogScope logScope, CreateLogItemRequest logRequest) { var communicationMessage = new AddLogCommunicationMessage() { ParentScopeId = logScope?.Id, Time = logRequest.Time, Text = logRequest.Text, Level = logRequest.Level }; if (logRequest.Attach != null) { communicationMessage.Attach = new Attach { Name = logRequest.Attach.Name, MimeType = logRequest.Attach.MimeType, Data = logRequest.Attach.Data }; } Console.WriteLine(ModelSerializer.Serialize <AddLogCommunicationMessage>(communicationMessage)); return(true); }
public LogMessageCommandArgs(ILogScope logScope, ILogMessage logMessage) { LogScope = logScope; LogMessage = logMessage; }
public static T CorrelationId <T>(this ILogScope scope) { return(scope.Property <T>()); }
public static ILogScope WithCorrelationContext(this ILogScope scope, object correlationContext) { return(scope.With("CorrelationContext", correlationContext)); }
public static ILogScope WithCorrelationId(this ILogScope scope) { return(scope.WithCorrelationId(Guid.NewGuid().ToString("N"))); }
public static ILogScope WithCorrelationId(this ILogScope scope, object correlationId) { return(scope.With("CorrelationId", correlationId)); }
/// <summary> /// Attaches elapsed-milliseconds to each log. /// </summary> public static ILogScope AttachElapsed(this ILogScope scope) { return(scope.With(new ElapsedMilliseconds(nameof(Elapsed)))); }
public static ILogScope WithCurrentRoutine(this ILogScope scope, [CallerMemberName] string identifier = null) { return(scope.WithRoutine(identifier)); }
public static ILogScope WithRoutine(this ILogScope scope, string identifier) { return(scope.With(nameof(WithRoutine), identifier)); }
public WorkerState(ILogScope expectedScope) { ExpectedScope = expectedScope; }
public static ILogScope WithCorrelationId(this ILogScope scope, out object correlationId) { return(scope.WithCorrelationId(correlationId = LogScope.NewCorrelationId())); }
public LogScopeCommandArgs(ILogScope logScope) { LogScope = logScope; }
public MethodInterceptor() { _parentScope = Log.ActiveScope; //Console.WriteLine($"Hi from .ctor: {_parentScope.Id}"); }