Beispiel #1
0
        public void WillLogLoggedOutUserAfterLogout()
        {
            //-- Arrange
            var userEnricher  = new SerilogUserLogEnricher();
            var expectedLevel = "Verbose";
            var expected      = "This is verbose message. MessagePayload { SomeString = \"some payload\" }";
            var actor         = new SerilogAdapter(new Serilog.LoggerConfiguration()
                                                   .Enrich.FromLogContext()
                                                   .WriteTo.MockConsoleForUser()
                                                   .MinimumLevel.Verbose());

            //-- Act
            userEnricher.UserLoggedIn(User);
            actor.Verbose(expected, new MessagePayload()
            {
                SomeString = "some payload"
            });
            Assert.AreEqual($"{expectedLevel}:[{User.UserName}] {expected}", MockFormatSink.LastLogEntry);
            userEnricher.UserLoggedOut();
            actor.Verbose(expected, new MessagePayload()
            {
                SomeString = "some payload"
            });

            //-- Assert
            Assert.AreEqual($"{expectedLevel}:[No-user] {expected}", MockFormatSink.LastLogEntry);
        }
        private static void SetupLogger(IWindsorContainer container)
        {
            //TODO: don't hard-wire the seriLog here !
            var adapter = new SerilogAdapter(SeriLogFactory.Create());

            container.Register(Component.For <ILogger>().Instance(adapter).LifestyleSingleton());
            Logger.SetCurrent(adapter);
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            var logger = new SerilogAdapter();

            logger.LogMessage("Logging message");

            Console.ReadLine();
        }
        public void WarningTest()
        {
            //-- Arrange
            var expectedLevel = "Warning";
            var expected      = "This is warning message. MessagePayload { SomeString = \"some payload\" }";
            var actor         = new SerilogAdapter(new Serilog.LoggerConfiguration()
                                                   .WriteTo.MockConsole()
                                                   .MinimumLevel.Warning());

            //-- Act
            actor.Warning(expected, new MessagePayload()
            {
                SomeString = "some payload"
            });


            //-- Assert
            Assert.AreEqual($"{expectedLevel}:{expected}", MockSink.LastLogEntry);
        }
Beispiel #5
0
        public void DebugLoggedUserTest()
        {
            //-- Arrange
            var userEnricher = new SerilogUserLogEnricher();

            var expectedLevel = "Debug";
            var expected      = "This is debug message.  MessagePayload { SomeString = \"some payload\" }";
            var actor         = new SerilogAdapter(new Serilog.LoggerConfiguration()
                                                   .Enrich.FromLogContext()
                                                   .WriteTo.MockConsoleForUser()
                                                   .MinimumLevel.Debug());

            //-- Act
            userEnricher.UserLoggedIn(User);
            actor.Debug <object>(expected, new MessagePayload()
            {
                SomeString = "some payload"
            });
            //-- Assert
            Assert.AreEqual($"{expectedLevel}:[{User.UserName}] {expected}", MockFormatSink.LastLogEntry);
        }
Beispiel #6
0
        public async Task <ExitCode> ExecuteAsync()
        {
            try
            {
                var parser = CreateParser();

                int exitCode;

                using (var serilogAdapter = new SerilogAdapter(_logger))
                {
                    exitCode = await parser.InvokeAsync(_args, serilogAdapter)
                               .ConfigureAwait(continueOnCapturedContext: false);
                }

                return(new ExitCode(exitCode));
            }
            catch (Exception ex) when(!ex.IsFatal())
            {
                _logger.Error(ex, "Could not create nuspec");
                return(ExitCode.Failure);
            }
        }
Beispiel #7
0
        private void InitializeLog()
        {
            SerilogAdapter = new SerilogAdapter(ReadLogger(), Section.Log.Level);

            Traits.InitializeLog(SerilogAdapter);
        }
 public void SerilogLoggerTest1()
 {
     var actual = new SerilogAdapter(new Serilog.LoggerConfiguration().WriteTo.MockConsole());
 }
 public void SerilogLoggerTest()
 {
     var actual = new SerilogAdapter();
 }