/// <summary> /// This configures Serilog with some defaults /// Such as adding ProcessID, Thread, AppDomain etc /// It is highly recommended that you keep/use this default in your own logging config customizations /// </summary> public static LoggerConfiguration MinimalConfiguration( this LoggerConfiguration logConfig, IHostEnvironment hostEnvironment, ILoggingConfiguration loggingConfiguration, UmbracoFileConfiguration umbracoFileConfiguration) { global::Serilog.Debugging.SelfLog.Enable(msg => System.Diagnostics.Debug.WriteLine(msg)); //Set this environment variable - so that it can be used in external config file //add key="serilog:write-to:RollingFile.pathFormat" value="%BASEDIR%\logs\log.txt" /> Environment.SetEnvironmentVariable("BASEDIR", hostEnvironment.MapPathContentRoot("/").TrimEnd("\\"), EnvironmentVariableTarget.Process); Environment.SetEnvironmentVariable("UMBLOGDIR", loggingConfiguration.LogDirectory, EnvironmentVariableTarget.Process); Environment.SetEnvironmentVariable("MACHINENAME", Environment.MachineName, EnvironmentVariableTarget.Process); logConfig.MinimumLevel.Verbose() //Set to highest level of logging (as any sinks may want to restrict it to Errors only) .Enrich.WithProcessId() .Enrich.WithProcessName() .Enrich.WithThreadId() .Enrich.WithProperty("ApplicationId", hostEnvironment.GetTemporaryApplicationId()) // Updated later by ApplicationIdEnricher .Enrich.WithProperty("MachineName", Environment.MachineName) .Enrich.With <Log4NetLevelMapperEnricher>() .Enrich.FromLogContext(); // allows us to dynamically enrich logConfig.WriteTo.UmbracoFile( path: umbracoFileConfiguration.GetPath(loggingConfiguration.LogDirectory), fileSizeLimitBytes: umbracoFileConfiguration.FileSizeLimitBytes, restrictedToMinimumLevel: umbracoFileConfiguration.RestrictedToMinimumLevel, rollingInterval: umbracoFileConfiguration.RollingInterval, flushToDiskInterval: umbracoFileConfiguration.FlushToDiskInterval, rollOnFileSizeLimit: umbracoFileConfiguration.RollOnFileSizeLimit, retainedFileCountLimit: umbracoFileConfiguration.RetainedFileCountLimit ); return(logConfig); }