Ejemplo n.º 1
0
        private static void Main()
        {
            var log = new LoggerConfiguration()
                      .MinimumLevel.Verbose()
                      .WriteTo.Console()
                      .WriteTo.File("log.txt",
                                    rollingInterval: RollingInterval.Day,
                                    rollOnFileSizeLimit: true,
                                    fileSizeLimitBytes: 512)
                      .CreateLogger();

            log.Information("Hello, Serilog!");

            var position  = new { Latitude = 25, Longitude = 134 };
            var elapsedMs = 34;
            var products  = new List <string> {
                "Paper", "Pencil", "Pen"
            };

            log.Information("Processed {Position} in {Elapsed} ms.", position, elapsedMs);
            log.Information("Ordered {@products}", products);
            log.Information("Added {UserName}", "Sarah");
            log.Information("Added {UserName:l}", "Sarah");
            log.Information("PI is {PI}", Math.PI);
            log.Information("PI is {PI:0.00}", Math.PI);
            log.Verbose("This is verbose.");
            log.Debug("This is debug.");
            log.Warning("This is warning");
            log.Error("This is error");
            log.Fatal("This is Fatal");

            Log.CloseAndFlush();
            Console.ReadKey();
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            var logger = new LoggerConfiguration()
                .MinimumLevel.Debug()
                .WriteTo.ColoredConsole()
                .WriteTo.Elasticsearch("http://localhost:9200")
                .CreateLogger();

            logger.Information("Here is an informational message");
            logger.Debug("Some debug level info");
            logger.Error("And error level info");
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {

            //Configuration by AppSettings
            var logger = new LoggerConfiguration()
                .ReadFrom.AppSettings()
                .MinimumLevel.Debug()
                .Enrich.WithThreadId()
                .Enrich.WithProperty("MyMetaProperty", "Oh! the beautiful value!")
                .WriteTo.ColoredConsole()
                .CreateLogger();

            ////Configuration by code
            //var logger = new LoggerConfiguration()
            //    .MinimumLevel.Debug()
            //    .Enrich.WithThreadId()
            //    .Enrich.WithProperty("MyMetaProperty", "Oh! the beautiful value!")
            //    .WriteTo.ColoredConsole()
            //    .WriteTo.BrowserConsole(port: 9999, buffer: 50)
            //    .CreateLogger();

            OpenBrowserToBrowserLogUrl();

            logger.Information("Hello!");
            Thread.Sleep(1000);
            for (int i = 0; i < 100000; i++)
            {
                logger.Information("Hello this is a log from a server-side process!");
                Thread.Sleep(100);
                logger.Warning("Hello this is a warning from a server-side process!");
                logger.Debug("... and here is another log again ({IndexLoop})", i);
                Thread.Sleep(200);
                try
                {
                    ThrowExceptionWithStackTrace(4);
                }
                catch (Exception ex)
                {
                    logger.Error(ex, "An error has occured, really?");
                }

                Thread.Sleep(1000);
            }
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            //Create Logger
            var logger = new LoggerConfiguration()
                         .MinimumLevel.Debug()
                         .WriteTo.ColoredConsole()
                         .WriteTo.RollingFile(@"C:\Users\Daniel Contreras\source\repos\Serilog\Serilog\Log-{Date}.txt")
                         .CreateLogger();
            // prepare data
            var order    = new { Id = 12, Total = 128.50, CustomerId = 72 };
            var customer = new { Id = 72, Name = "John Smith" };

            // write log message
            logger.Information("New orders {OrderId} by {Customer}", order.Id, customer);
            logger.Debug("Debugging message");
            logger.Information("Information message");
            logger.Warning("Warning message");
            logger.Error("Error message");
            logger.Fatal("Fatal message");
            Console.ReadKey();
        }
Ejemplo n.º 5
0
        public static void Main(string[] args)
        {
            var log = new LoggerConfiguration()
                .WriteTo.Console()
                .MinimumLevel.Debug()
                .CreateLogger();

            var options = new Options();
            if (CommandLine.Parser.Default.ParseArguments(args, options) == false)
            {
                log.Fatal("Problem parsing options!");
                Environment.Exit(-1);
            }

            log.Information("Processing migrations");
            var connectionStringVal = Config.ConnectionStrings[options.ConnectionStringName];
            if (connectionStringVal == null)
            {
                log.Fatal("ERROR: Unable to get connection string from configuration");
                Environment.Exit(-2);
            }

            var connectionString = connectionStringVal.ConnectionString;
            log.Debug("Connection string is {connectionString}", connectionString);

            var runner = new FluentRunner(connectionString, typeof(DipsContext).Assembly);

            try
            {
                runner.MigrateToLatest();
            }
            catch (Exception e)
            {
                log.Fatal(e, "ERROR: problem while running migrations!");
                Environment.Exit(-3);
            }

            log.Information("Migrations run successfully");
        }