public void ShouldClearAllDestinations()
        {
            //setup
            var triggered = false;
            var dest1     = new EventDestination(LogLevels.Debug);

            dest1.LoggingEvent += (sender, args) => triggered = true;
            var dest2 = new EventDestination(LogLevels.Debug);

            dest2.LoggingEvent += (sender, args) => triggered = true;
            var dest3 = new EventDestination(LogLevels.Debug);

            dest3.LoggingEvent += (sender, args) => triggered = true;
            Utilities.Logger.ClearDestinations();

            //act
            Utilities.Logger.AddDestination(dest1);
            Utilities.Logger.AddDestination(dest2);
            Utilities.Logger.AddDestination(dest3);
            Utilities.Logger.ClearDestinations();
            Utilities.Logger.Debug("Hello World!");

            //assert
            triggered.Should().BeFalse();
        }
        public void ShouldRemoveDestinationEvenIfNotInList()
        {
            //setup
            var dest = new EventDestination(LogLevels.Debug);

            //act
            Utilities.Logger.RemoveDestination(dest);

            //assert that no exception was thrown
        }
Ejemplo n.º 3
0
 private void SetupTriggers()
 {
     foreach (LogLevels num in Enum.GetValues(typeof(LogLevels)))
     {
         _triggers.Add(num, false);
         var ev = new EventDestination(num);
         ev.LoggingEvent += (sender, args) => _triggers[num] = true;
         Utilities.Logger.AddDestination(ev);
         _destinations.Add(num, ev);
     }
 }
        public void ShouldRemoveDestination()
        {
            //setup
            var triggered = false;
            var dest      = new EventDestination(LogLevels.Debug);

            dest.LoggingEvent += (sender, args) => triggered = true;

            //act
            Utilities.Logger.AddDestination(dest);
            Utilities.Logger.RemoveDestination(dest);
            Utilities.Logger.Debug("Hello World!");

            //assert
            triggered.Should().BeFalse();
        }
Ejemplo n.º 5
0
        public void ShouldTriggerErrorOnError()
        {
            var triggered = false;
            var dest      = new EventDestination(LogLevels.Error);

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

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

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

            //cleanup
            Utilities.Logger.RemoveDestination(dest);
        }
Ejemplo n.º 6
0
        public void ShouldTriggerSecurityOnSecurity()
        {
            var triggered = false;
            var dest      = new EventDestination(LogLevels.Security);

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

            //act
            Utilities.Logger.Security("Hello World!");

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

            //cleanup
            Utilities.Logger.RemoveDestination(dest);
        }
Ejemplo n.º 7
0
        public void ShouldTriggerEventWhenLoggingMessage()
        {
            //setup
            var triggered = false;
            var dest      = new EventDestination(LogLevels.Debug);

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

            //act
            Utilities.Logger.Debug("Hello World!");

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

            //cleanup
            Utilities.Logger.RemoveDestination(dest);
        }
Ejemplo n.º 8
0
        public void ShouldContainException()
        {
            //setup
            var e          = new Exception("Hello World!");
            var evtMessage = string.Empty;
            var d          = new EventDestination(LogLevels.Error);

            d.LoggingEvent += (sender, args) => evtMessage = args.Message;
            Utilities.Logger.AddDestination(d);

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

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

            //cleanup
            Utilities.Logger.RemoveDestination(d);
        }
Ejemplo n.º 9
0
        public void ShouldNotContainMessageLevelNamed()
        {
            //setup
            const string msg        = "Hello World!";
            var          evtMessage = string.Empty;
            var          d          = new EventDestination("NOT_VALID");

            d.LoggingEvent += (sender, args) => evtMessage = args.Message;
            Utilities.Logger.AddDestination(d);

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


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

            //cleanup
            Utilities.Logger.RemoveDestination(d);
        }
Ejemplo n.º 10
0
        public void ShouldContainMessageLevelInt()
        {
            //setup
            const string msg        = "Hello World!";
            var          evtMessage = string.Empty;
            var          d          = new EventDestination(LogLevels.Debug.GetHashCode());

            d.LoggingEvent += (sender, args) => evtMessage = args.Message;
            Utilities.Logger.AddDestination(d);

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


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

            //cleanup
            Utilities.Logger.RemoveDestination(d);
        }
Ejemplo n.º 11
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            Logger.AddDestination(new ConsoleDestination());
            Logger.Debug("Hello World!");

            var ex = new Exception("This is a specific Exception Message and will contain a stack trace.");

            Logger.Error(ex, "This is a generic message about what happened.");


            var ex2 = new Exception("This exception has an inner exception. (likely details to hide from a UI)", ex);

            Logger.Error(ex2, "Another generic message about an error occuring. (friendly message to show a UI maybe?)");


            var dest = new FileDestination("test.log", LogLevels.Warning, false, FileDestination.EncodingOptions.UTF8);

            var evtDest = new EventDestination(LogLevels.Debug);

            evtDest.LoggingEvent += (sender, eventArgs) => { /* whatever you want to do with the message here */ };
        }