コード例 #1
0
        public TopshelfSerilogBootstrapper()
        {
            // Common Initial
            var loggerConfiguration = new LoggerConfiguration()
                                      .Enrich.FromLogContext()
                                      .Enrich.WithEnvironmentUserName()
                                      .Enrich.WithMachineName()
                                      .MinimumLevel.Is(Serilog.Events.LogEventLevel.Debug)
                                      .MinimumLevel.Override("MassTransit", Serilog.Events.LogEventLevel.Warning)
                                      .WriteTo.Console()
                                      .WriteTo.AzureDocumentDB(
                "https://<yourcosmodb>.documents.azure.com:443/",
                Environment.GetEnvironmentVariable("CosmoDbAuthKey"),
                "Logs",
                "StarterKitDoSomeWork",
                timeToLive: 86400);

            // Common Final
            Log.Logger = loggerConfiguration.CreateLogger();

            // Configure Topshelf Logger
            SerilogLogWriterFactory.Use(Log.Logger);

            // MassTransit to use Serilog
            SerilogLogger.Use();
        }
コード例 #2
0
        public void Before_any_tests()
        {
            _baseLogger = new LoggerConfiguration()
                          .MinimumLevel.Debug()
                          .WriteTo.Console()
                          .CreateLogger();

            SerilogLogger.Use(_baseLogger);
        }
コード例 #3
0
        /// <summary> Configure the Mass Transit Service Bus to use the provided Serilog. </summary>
        /// <param name="configurator"> The configurator to act on. </param>
        /// <param name="baseLogger"> (Optional) The base logger. If none supplied, will use the global logger. </param>
        /// <param name="demoteDebug"> Force "Debug" level logging from MassTransit to be demoted to Verbose.</param>
        public static void UseSerilog(this IBusFactoryConfigurator configurator, ILogger baseLogger = null, bool demoteDebug = false)
        {
            if (configurator == null)
            {
                throw new ArgumentNullException("configurator");
            }

            SerilogLogger.Use(baseLogger, demoteDebug);
        }
コード例 #4
0
        static void ConfigureSerilog()
        {
            Log.Logger = new LoggerConfiguration()
                         .MinimumLevel.Debug()
                         .WriteTo.Console()
                         .CreateLogger();

            // Configure Topshelf Logger
            SerilogLogWriterFactory.Use(Log.Logger);

            // MassTransit to use Serilog
            SerilogLogger.Use(Log.Logger);
        }