Example #1
0
        public void ShouldContainMessageExceptionAndMetadata()
        {
            //setup
            const string msg        = "Goodbye Everyone";
            var          e          = new Exception("Hello World!");
            var          evtMessage = string.Empty;
            var          exMessage  = string.Empty;
            TestObject   evtObject  = null;
            var          d          = new GenericEventDestination <TestObject>(LogLevels.Error);

            d.LoggingEvent += (sender, args) =>
            {
                evtMessage = args.Message;
                evtObject  = args.Metadata;
                exMessage  = args.Exception.Message;
            };

            Utilities.Logger.AddDestination(d);
            var obj = new TestObject("ok", 2);

            //act
            Utilities.Logger.Error(e, obj, msg);

            //assert
            evtMessage.Should().Contain(msg);
            exMessage.Should().Contain(e.Message);
            evtObject.Should().NotBeNull();
            evtObject.Name.Should().Be(obj.Name);
            evtObject.Value.Should().Be(obj.Value);

            //cleanup
            Utilities.Logger.RemoveDestination(d);
        }
 private void SetupTriggers()
 {
     foreach (LogLevels num in Enum.GetValues(typeof(LogLevels)))
     {
         _triggers.Add(num, false);
         var ev = new GenericEventDestination <bool>(num);
         ev.LoggingEvent += (sender, args) => _triggers[num] = args.Metadata;
         Utilities.Logger.AddDestination(ev);
         _destinations.Add(num, ev);
     }
 }
Example #3
0
        public void ShouldTriggerErrorOnError()
        {
            var triggered = false;
            var dest      = new GenericEventDestination <bool>(LogLevels.Error);

            dest.LoggingEvent += (sender, args) => triggered = args.Metadata;
            Utilities.Logger.AddDestination(dest);

            //act
            Utilities.Logger.Error(new Exception("Hello World!"), true);

            //assert
            triggered.Should().BeTrue();

            //cleanup
            Utilities.Logger.RemoveDestination(dest);
        }
        public void ShouldTriggerWarnOnWarn()
        {
            var triggered = false;
            var dest      = new GenericEventDestination <myMetadata>(LogLevels.Warning);

            dest.LoggingEvent += (sender, args) => triggered = args.Metadata.State;
            Utilities.Logger.AddDestination(dest);
            var ctx = new myMetadata();

            //act
            ctx.Warn("Hello World!");

            //assert
            triggered.Should().BeTrue();

            //cleanup
            Utilities.Logger.RemoveDestination(dest);
        }
Example #5
0
        public void ShouldContainException()
        {
            //setup
            var e          = new Exception("Hello World!");
            var evtMessage = string.Empty;
            var d          = new GenericEventDestination <TestObject>(LogLevels.Error);

            d.LoggingEvent += (sender, args) => evtMessage = args.Exception.Message;
            Utilities.Logger.AddDestination(d);
            var obj = new TestObject("what?", 67);

            //act
            Utilities.Logger.Error(e, obj, "Goodbye Everyone");

            //assert
            evtMessage.Should().Contain(e.Message);

            //cleanup
            Utilities.Logger.RemoveDestination(d);
        }
Example #6
0
        public void ShouldContainMessage()
        {
            //setup
            const string msg        = "Hello World!";
            var          evtMessage = string.Empty;
            var          d          = new GenericEventDestination <TestObject>(LogLevels.Debug);

            d.LoggingEvent += (sender, args) => evtMessage = args.Message;
            Utilities.Logger.AddDestination(d);
            var obj = new TestObject("blarg", 5);

            //act
            Utilities.Logger.Debug(msg, obj);

            //assert
            evtMessage.Should().Contain(msg);

            //cleanup
            Utilities.Logger.RemoveDestination(d);
        }