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
        public static void Init()
        {
            var logger = new Serilog.LoggerConfiguration()
                         .MinimumLevel.Debug()
                         .Enrich.FromLogContext()
                         .WriteTo.Async(x => x.File("fork.serilog", fileSizeLimitBytes: 104857600))
                         .CreateLogger();

            AppDomain.CurrentDomain.UnhandledException += (s, e) =>
            {
                logger.Fatal(e.ExceptionObject as Exception, "Unhandled exception");
            };

            var forkConfig = AppConfigParser.Parse();

            bufferSize = forkConfig.DestinationsBufferSize;
            fork       = forkConfig.CreateFork(logger);
            fork.Run();

            instance = new ObservableCollection <ViewEntry>(forkConfig.Destinations.Select(x =>
                                                                                           new ViewEntry
            {
                Address     = x.Id,
                BufferState = string.Empty,
                Kind        = "Destination",
                State       = true
            }).Prepend(new ViewEntry
            {
                Address     = forkConfig.Source.Id,
                BufferState = string.Empty,
                Kind        = "Source",
                State       = true
            }));
        }
Ejemplo n.º 3
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");
        }
		public void Fatal( LoggerHistorySink sut, string message, FatalApplicationException error )
		{
			var logger = new LoggerConfiguration().WriteTo.Sink( sut ).CreateLogger();

			logger.Fatal( error, message );

			var item = sut.Events.Only();
			Assert.NotNull( item );

			Assert.Equal( LogEventLevel.Fatal, item.Level );
			Assert.Contains( message, item.RenderMessage() );
			Assert.Equal( error, item.Exception );
		}
Ejemplo n.º 5
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.º 6
0
        static void Main(string[] args)
        {
            var log = new LoggerConfiguration()
                          .WriteTo.ColoredConsole()
                          .CreateLogger();

            try
            {
                // https://github.com/serilog/serilog/wiki/Getting-Started
                //log.Information("Starting log...");

                var array = new int[] { 3, 1, 2, 4, 3 };
                var result = TimeComplexity.solutionTapeEquilibrium(array);

                log.Information($"Result:{result}.");
                Console.ReadLine();
            }
            catch (Exception exception)
            {
                log.Fatal(exception, "Fatal error");
            }
        }