Пример #1
1
        public Program()
        {
            // a DI based application would get ILoggerFactory injected instead
            var factory = new LoggerFactory();

            // getting the logger immediately using the class's name is conventional
            _logger = factory.CreateLogger(typeof(Program).FullName);

            // providers may be added to an ILoggerFactory at any time, existing ILoggers are updated
            #if !DNXCORE50
            factory.AddNLog(new global::NLog.LogFactory());
            #endif
            factory.AddConsole();
            factory.AddConsole((category, logLevel) => logLevel >= LogLevel.Critical && category.Equals(typeof(Program).FullName));
        }
Пример #2
0
        public void Execute(string[] args)
        {
            var options = new Options();
            Parser.Default.ParseArguments(args, options);

            var factory = new LoggerFactory();
            factory.AddNLog(SetupNLog());

            var logger = factory.CreateLogger("category-1");

            int number = options.Number;
            for (int i = 0; i < number; i++)
                logger.LogInformation("message " + i);
        }
Пример #3
0
        public Program()
        {
            // a DI based application would get ILoggerFactory injected instead
            var factory = new LoggerFactory();

            // getting the logger immediately using the class's name is conventional
            _logger = factory.CreateLogger(typeof(Program).FullName);

            // providers may be added to an ILoggerFactory at any time, existing ILoggers are updated
            #if !DNXCORE50
            factory.AddNLog(new global::NLog.LogFactory());

            factory.AddSerilog(new Serilog.LoggerConfiguration()
                .Enrich.WithMachineName()
                .Enrich.WithProcessId()
                .Enrich.WithThreadId()
                .MinimumLevel.Debug()
                .WriteTo.RollingFile("file-{Date}.txt", outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} {Level}:{EventId} [{SourceContext}] {Message}{NewLine}{Exception}")
                .WriteTo.Sink(new RollingFileSink("file-{Date}.json", new JsonFormatter(), null, null))
                .WriteTo.Sink(new FileSink("dump.txt", new RawFormatter(), null)));
            #endif
            factory.AddConsole();
            factory.AddConsole((category, logLevel) => logLevel >= LogLevel.Critical && category.Equals(typeof(Program).FullName));
        }