示例#1
0
        protected override IRuntime GetRuntime()
        {
            var logger = SerilogLogger.CreateWithDefaultConfiguration();

            var runtime = new WebRuntime(this, logger, GetMainDom(logger));

            return(runtime);
        }
示例#2
0
        /// <summary>
        /// Create and configure the logger
        /// </summary>
        public static IServiceCollection AddLogger(
            this IServiceCollection services,
            IHostingEnvironment hostingEnvironment,
            ILoggingConfiguration loggingConfiguration,
            IConfiguration configuration)
        {
            // Create a serilog logger
            var logger = SerilogLogger.CreateWithDefaultConfiguration(hostingEnvironment, loggingConfiguration, configuration, out var umbracoFileConfig);

            services.AddSingleton(umbracoFileConfig);

            // This is nessasary to pick up all the loggins to MS ILogger.
            Log.Logger = logger.SerilogLog;

            // Wire up all the bits that serilog needs. We need to use our own code since the Serilog ext methods don't cater to our needs since
            // we don't want to use the global serilog `Log` object and we don't have our own ILogger implementation before the HostBuilder runs which
            // is the only other option that these ext methods allow.
            // I have created a PR to make this nicer https://github.com/serilog/serilog-extensions-hosting/pull/19 but we'll need to wait for that.
            // Also see : https://github.com/serilog/serilog-extensions-hosting/blob/dev/src/Serilog.Extensions.Hosting/SerilogHostBuilderExtensions.cs

            services.AddLogging(configure =>
            {
                configure.AddSerilog(logger.SerilogLog, false);
            });

            // This won't (and shouldn't) take ownership of the logger.
            services.AddSingleton(logger.SerilogLog);

            // Registered to provide two services...
            var diagnosticContext = new DiagnosticContext(logger.SerilogLog);

            // Consumed by e.g. middleware
            services.AddSingleton(diagnosticContext);

            // Consumed by user code
            services.AddSingleton <IDiagnosticContext>(diagnosticContext);
            services.AddSingleton(loggingConfiguration);

            return(services);
        }
示例#3
0
 protected virtual ILogger GetLogger()
 => Logger ?? SerilogLogger.CreateWithDefaultConfiguration();     // TODO: Remove this in netcore, this purely just backwards compat ugliness
示例#4
0
 /// <summary>
 /// Gets a logger.
 /// </summary>
 protected virtual ILogger GetLogger()
 => SerilogLogger.CreateWithDefaultConfiguration();