Esempio n. 1
0
        public static void Main(string[] args)
        {
            var loggerFactory = new LoggerFactory();

            // This will write (1) to console with colors, and (2) to a rolling file with a custom formatting.
            loggerFactory.AddSerilog(
                new LoggerConfiguration()
                    .WriteTo.ColoredConsole()
                    .WriteTo.RollingFile( "dailylogs.log", Serilog.Events.LogEventLevel.Warning, "@{Timestamp:HH:mm:ss.fff} --- {Message}{NewLine}{Exception}{NewLine}")              
            );

            var log = loggerFactory.Create("My test app");

            log.WriteVerbose("This is verbose -- won't show up by default");
            log.WriteInformation("This is just for your information");
            log.WriteCritical("Something critical");
            log.WriteWarning("just a warning");
            log.WriteCritical("Another critical event, causing an exception", new Exception("testException"));

        }