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);
        }
Beispiel #3
0
        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));
        }
Beispiel #5
0
        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));
        }
Beispiel #7
0
        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));
        }
Beispiel #8
0
        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);
        }
Beispiel #9
0
        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);
        }
Beispiel #10
0
 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);
        }
Beispiel #12
0
 public LogMessageCommandArgs(ILogScope logScope, ILogMessage logMessage)
 {
     LogScope   = logScope;
     LogMessage = logMessage;
 }
Beispiel #13
0
 public static T CorrelationId <T>(this ILogScope scope)
 {
     return(scope.Property <T>());
 }
Beispiel #14
0
 public static ILogScope WithCorrelationContext(this ILogScope scope, object correlationContext)
 {
     return(scope.With("CorrelationContext", correlationContext));
 }
Beispiel #15
0
 public static ILogScope WithCorrelationId(this ILogScope scope)
 {
     return(scope.WithCorrelationId(Guid.NewGuid().ToString("N")));
 }
Beispiel #16
0
 public static ILogScope WithCorrelationId(this ILogScope scope, object correlationId)
 {
     return(scope.With("CorrelationId", correlationId));
 }
Beispiel #17
0
 /// <summary>
 /// Attaches elapsed-milliseconds to each log.
 /// </summary>
 public static ILogScope AttachElapsed(this ILogScope scope)
 {
     return(scope.With(new ElapsedMilliseconds(nameof(Elapsed))));
 }
Beispiel #18
0
 public static ILogScope WithCurrentRoutine(this ILogScope scope, [CallerMemberName] string identifier = null)
 {
     return(scope.WithRoutine(identifier));
 }
Beispiel #19
0
 public static ILogScope WithRoutine(this ILogScope scope, string identifier)
 {
     return(scope.With(nameof(WithRoutine), identifier));
 }
Beispiel #20
0
 public WorkerState(ILogScope expectedScope)
 {
     ExpectedScope = expectedScope;
 }
Beispiel #21
0
 public static ILogScope WithCorrelationId(this ILogScope scope, out object correlationId)
 {
     return(scope.WithCorrelationId(correlationId = LogScope.NewCorrelationId()));
 }
 public LogScopeCommandArgs(ILogScope logScope)
 {
     LogScope = logScope;
 }
Beispiel #23
0
 public MethodInterceptor()
 {
     _parentScope = Log.ActiveScope;
     //Console.WriteLine($"Hi from .ctor: {_parentScope.Id}");
 }