Example #1
0
        public void TypeBracketWidth_ForNullSourceTypeAndMethod_ShouldInformAboutUnknownSourceTypeAndMethod()
        {
            var formatter = new SimpleMessageFormatter();

            const string description = "Test";
            var          dateTime    = new DateTime();

            var text = formatter.Format(new Message(description, MessageType.Trace, null),
                                        new MessageContext(default(MessageSource), dateTime));

            Assert.That(text.Contains("<unknown_type::unknown_method>"));
        }
Example #2
0
        public void TypeBracketWidth_ForAllTypes_ShouldBeTheSame()
        {
            var formatter = new SimpleMessageFormatter();

            const string description = "Test";
            var          context     = new MessageContext(default(MessageSource), new DateTime());

            // only message type is different so all formatted texts should have same length

            int width = formatter.Format(new Message(description, MessageType.Trace, null), context).Length;

            Assert.That(formatter.Format(new Message(description, MessageType.Debug, null), context).Length,
                        Is.EqualTo(width));

            Assert.That(formatter.Format(new Message(description, MessageType.Warning, null), context).Length,
                        Is.EqualTo(width));

            Assert.That(formatter.Format(new Message(description, MessageType.Error, null), context).Length,
                        Is.EqualTo(width));
        }
Example #3
0
        public MainWindow()
        {
            InitializeComponent();

            var simpleMessageFormatter = new SimpleMessageFormatter();

            ListBox listBox = (ListBox)this.FindName("ListBox");

            var listBoxMessageAppender = new ListBoxMessageAppender(simpleMessageFormatter, listBox);
            var fileMessageAppender    = new FileMessageAppender(simpleMessageFormatter, "log.txt");

            var messageAppenders = new IMessageAppender[]
            {
                fileMessageAppender,
                listBoxMessageAppender
            };

            this.logger = new Logger(messageAppenders);

            this.KeyDown += MainWindowKeyDown;
        }
        static void Main(string[] args)
        {
            var simpleMessageFormatter = new SimpleMessageFormatter();
            var xmlMessageFormatter    = new XMLMessageFormatter();
            var jsonMessageFormatter   = new JsonFormatter();

            var fileMessageAppender    = new FileMessageAppender(jsonMessageFormatter, "log.txt");
            var consoleMessageAppender = new ConsoleMessageAppender(jsonMessageFormatter);

            var messageAppenders = new IMessageAppender[]
            {
                fileMessageAppender,
                consoleMessageAppender
            };

            Logger logger = new Logger(messageAppenders);

            logger.LogCriticalError("Out of memory");
            logger.LogInfo("Unused local variable 'name'");

            fileMessageAppender.CloseWriter();
        }