Moved serilog config to appsettings and configured it to also catch MS logging messages.
Added Console log for Development
This commit is contained in:
@@ -119,10 +119,11 @@ namespace Umbraco.Extensions
|
||||
/// </summary>
|
||||
/// <param name="services"></param>
|
||||
/// <param name="webHostEnvironment"></param>
|
||||
/// <param name="configuration"></param>
|
||||
/// <returns></returns>
|
||||
public static IServiceCollection AddUmbracoCore(this IServiceCollection services, IWebHostEnvironment webHostEnvironment)
|
||||
public static IServiceCollection AddUmbracoCore(this IServiceCollection services, IWebHostEnvironment webHostEnvironment, IConfiguration configuration)
|
||||
{
|
||||
return services.AddUmbracoCore(webHostEnvironment, out _);
|
||||
return services.AddUmbracoCore(webHostEnvironment, configuration, out _);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -130,9 +131,10 @@ namespace Umbraco.Extensions
|
||||
/// </summary>
|
||||
/// <param name="services"></param>
|
||||
/// <param name="webHostEnvironment"></param>
|
||||
/// <param name="configuration"></param>
|
||||
/// <param name="factory"></param>
|
||||
/// <returns></returns>
|
||||
public static IServiceCollection AddUmbracoCore(this IServiceCollection services, IWebHostEnvironment webHostEnvironment, out IFactory factory)
|
||||
public static IServiceCollection AddUmbracoCore(this IServiceCollection services, IWebHostEnvironment webHostEnvironment, IConfiguration configuration, out IFactory factory)
|
||||
{
|
||||
if (!UmbracoServiceProviderFactory.IsActive)
|
||||
throw new InvalidOperationException("Ensure to add UseUmbraco() in your Program.cs after ConfigureWebHostDefaults to enable Umbraco's service provider factory");
|
||||
@@ -140,12 +142,11 @@ namespace Umbraco.Extensions
|
||||
var umbContainer = UmbracoServiceProviderFactory.UmbracoContainer;
|
||||
|
||||
var loggingConfig = new LoggingConfiguration(
|
||||
Path.Combine(webHostEnvironment.ContentRootPath, "App_Data", "Logs"),
|
||||
Path.Combine(webHostEnvironment.ContentRootPath, "config", "serilog.config"),
|
||||
Path.Combine(webHostEnvironment.ContentRootPath, "config", "serilog.user.config"));
|
||||
Path.Combine(webHostEnvironment.ContentRootPath, "umbraco", "logs"));
|
||||
|
||||
IHttpContextAccessor httpContextAccessor = new HttpContextAccessor();
|
||||
services.AddSingleton<IHttpContextAccessor>(httpContextAccessor);
|
||||
services.AddSingleton<ILoggingConfiguration>(loggingConfig);
|
||||
|
||||
var requestCache = new GenericDictionaryRequestAppCache(() => httpContextAccessor.HttpContext?.Items);
|
||||
var appCaches = new AppCaches(
|
||||
@@ -158,6 +159,7 @@ namespace Umbraco.Extensions
|
||||
Assembly.GetEntryAssembly(),
|
||||
appCaches,
|
||||
loggingConfig,
|
||||
configuration,
|
||||
out factory);
|
||||
|
||||
return services;
|
||||
@@ -182,8 +184,9 @@ namespace Umbraco.Extensions
|
||||
Assembly entryAssembly,
|
||||
AppCaches appCaches,
|
||||
ILoggingConfiguration loggingConfiguration,
|
||||
IConfiguration configuration,
|
||||
out IFactory factory)
|
||||
=> services.AddUmbracoCore(webHostEnvironment, umbContainer, entryAssembly, appCaches, loggingConfiguration, GetCoreRuntime, out factory);
|
||||
=> services.AddUmbracoCore(webHostEnvironment, umbContainer, entryAssembly, appCaches, loggingConfiguration, configuration, GetCoreRuntime, out factory);
|
||||
|
||||
|
||||
/// <summary>
|
||||
@@ -206,6 +209,7 @@ namespace Umbraco.Extensions
|
||||
Assembly entryAssembly,
|
||||
AppCaches appCaches,
|
||||
ILoggingConfiguration loggingConfiguration,
|
||||
IConfiguration configuration,
|
||||
// TODO: Yep that's extremely ugly
|
||||
Func<Configs, IUmbracoVersion, IIOHelper, Core.Logging.ILogger, IProfiler, Core.Hosting.IHostingEnvironment, IBackOfficeInfo, ITypeFinder, AppCaches, IDbProviderFactoryCreator, IRuntime> getRuntime,
|
||||
out IFactory factory)
|
||||
@@ -241,6 +245,7 @@ namespace Umbraco.Extensions
|
||||
configs,
|
||||
webHostEnvironment,
|
||||
loggingConfiguration,
|
||||
configuration,
|
||||
out var logger, out var ioHelper, out var hostingEnvironment, out var backOfficeInfo, out var profiler);
|
||||
|
||||
var globalSettings = configs.Global();
|
||||
@@ -248,7 +253,7 @@ namespace Umbraco.Extensions
|
||||
var typeFinder = CreateTypeFinder(logger, profiler, webHostEnvironment, entryAssembly, configs.TypeFinder());
|
||||
|
||||
var runtime = getRuntime(
|
||||
configs,
|
||||
configs,
|
||||
umbracoVersion,
|
||||
ioHelper,
|
||||
logger,
|
||||
@@ -291,7 +296,7 @@ namespace Umbraco.Extensions
|
||||
var mainDom = new MainDom(logger, mainDomLock);
|
||||
|
||||
var coreRuntime = new CoreRuntime(
|
||||
configs,
|
||||
configs,
|
||||
umbracoVersion,
|
||||
ioHelper,
|
||||
logger,
|
||||
@@ -312,6 +317,7 @@ namespace Umbraco.Extensions
|
||||
Configs configs,
|
||||
IWebHostEnvironment webHostEnvironment,
|
||||
ILoggingConfiguration loggingConfiguration,
|
||||
IConfiguration configuration,
|
||||
out Core.Logging.ILogger logger,
|
||||
out IIOHelper ioHelper,
|
||||
out Core.Hosting.IHostingEnvironment hostingEnvironment,
|
||||
@@ -326,8 +332,7 @@ namespace Umbraco.Extensions
|
||||
|
||||
hostingEnvironment = new AspNetCoreHostingEnvironment(hostingSettings, webHostEnvironment);
|
||||
ioHelper = new IOHelper(hostingEnvironment);
|
||||
logger = AddLogger(services, hostingEnvironment, loggingConfiguration);
|
||||
|
||||
logger = AddLogger(services, hostingEnvironment, loggingConfiguration, configuration);
|
||||
backOfficeInfo = new AspNetCoreBackOfficeInfo(globalSettings);
|
||||
profiler = GetWebProfiler(hostingEnvironment);
|
||||
|
||||
@@ -338,10 +343,14 @@ namespace Umbraco.Extensions
|
||||
/// Create and configure the logger
|
||||
/// </summary>
|
||||
/// <param name="hostingEnvironment"></param>
|
||||
private static Core.Logging.ILogger AddLogger(IServiceCollection services, Core.Hosting.IHostingEnvironment hostingEnvironment, ILoggingConfiguration loggingConfiguration)
|
||||
private static Core.Logging.ILogger AddLogger(IServiceCollection services, Core.Hosting.IHostingEnvironment hostingEnvironment, ILoggingConfiguration loggingConfiguration, IConfiguration configuration)
|
||||
{
|
||||
// Create a serilog logger
|
||||
var logger = SerilogLogger.CreateWithDefaultConfiguration(hostingEnvironment, loggingConfiguration);
|
||||
var logger = SerilogLogger.CreateWithDefaultConfiguration(hostingEnvironment, loggingConfiguration, configuration);
|
||||
|
||||
// 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
|
||||
@@ -349,6 +358,11 @@ namespace Umbraco.Extensions
|
||||
// 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();
|
||||
// });
|
||||
|
||||
services.AddSingleton<ILoggerFactory>(services => new SerilogLoggerFactory(logger.SerilogLog, false));
|
||||
|
||||
// This won't (and shouldn't) take ownership of the logger.
|
||||
|
||||
Reference in New Issue
Block a user