private IEnumerable <FileInfo> GetAllIconsFiles() { var icons = new HashSet <FileInfo>(new CaseInsensitiveFileInfoComparer()); // add icons from plugins var appPluginsDirectoryPath = _hostingEnvironment.MapPathContentRoot(Constants.SystemDirectories.AppPlugins); if (Directory.Exists(appPluginsDirectoryPath)) { var appPlugins = new DirectoryInfo(appPluginsDirectoryPath); // iterate sub directories of app plugins foreach (var dir in appPlugins.EnumerateDirectories()) { // AppPluginIcons path was previoulsy the wrong case, so we first check for the prefered directory // and then check the legacy directory. var iconPath = _hostingEnvironment.MapPathContentRoot($"{Constants.SystemDirectories.AppPlugins}/{dir.Name}{Constants.SystemDirectories.PluginIcons}"); var iconPathExists = Directory.Exists(iconPath); if (!iconPathExists) { iconPath = _hostingEnvironment.MapPathContentRoot($"{Constants.SystemDirectories.AppPlugins}/{dir.Name}{Constants.SystemDirectories.AppPluginIcons}"); iconPathExists = Directory.Exists(iconPath); } if (iconPathExists) { var dirIcons = new DirectoryInfo(iconPath).EnumerateFiles("*.svg", SearchOption.TopDirectoryOnly); icons.UnionWith(dirIcons); } } } var iconFolder = _webHostEnvironment.WebRootFileProvider.GetDirectoryContents(_globalSettings.IconsPath); var coreIcons = iconFolder .Where(x => !x.IsDirectory && x.Name.EndsWith(".svg")) .Select(x => new FileInfo(x.PhysicalPath)); icons.UnionWith(coreIcons); return(icons); }
/// <summary> /// Outputs a CLEF format JSON log at /App_Data/Logs/ /// </summary> /// <param name="logConfig">A Serilog LoggerConfiguration</param> /// <param name="loggingConfiguration">The logging configuration</param> /// <param name="minimumLevel">The log level you wish the JSON file to collect - default is Verbose (highest)</param> /// <param name="retainedFileCount">The number of days to keep log files. Default is set to null which means all logs are kept</param> public static LoggerConfiguration OutputDefaultJsonFile( this LoggerConfiguration logConfig, Umbraco.Cms.Core.Hosting.IHostingEnvironment hostingEnvironment, ILoggingConfiguration loggingConfiguration, LogEventLevel minimumLevel = LogEventLevel.Verbose, int?retainedFileCount = null) { // .clef format (Compact log event format, that can be imported into local SEQ & will make searching/filtering logs easier) // Ends with ..txt as Date is inserted before file extension substring logConfig.WriteTo.File(new CompactJsonFormatter(), Path.Combine(hostingEnvironment.MapPathContentRoot(Cms.Core.Constants.SystemDirectories.LogFiles), $"UmbracoTraceLog.{Environment.MachineName}..json"), shared: true, rollingInterval: RollingInterval.Day, // Create a new JSON file every day retainedFileCountLimit: retainedFileCount, // Setting to null means we keep all files - default is 31 days restrictedToMinimumLevel: minimumLevel); return(logConfig); }
/// <summary> /// Outputs a .txt format log at /App_Data/Logs/ /// </summary> /// <param name="logConfig">A Serilog LoggerConfiguration</param> /// <param name="loggingConfiguration"></param> /// <param name="minimumLevel">The log level you wish the JSON file to collect - default is Verbose (highest)</param> /// <param name="retainedFileCount">The number of days to keep log files. Default is set to null which means all logs are kept</param> public static LoggerConfiguration OutputDefaultTextFile( this LoggerConfiguration logConfig, Umbraco.Cms.Core.Hosting.IHostingEnvironment hostingEnvironment, LogEventLevel minimumLevel = LogEventLevel.Verbose) { //Main .txt logfile - in similar format to older Log4Net output //Ends with ..txt as Date is inserted before file extension substring logConfig.WriteTo.File(Path.Combine(hostingEnvironment.MapPathContentRoot(Cms.Core.Constants.SystemDirectories.LogFiles), $"UmbracoTraceLog.{Environment.MachineName}..txt"), shared: true, rollingInterval: RollingInterval.Day, restrictedToMinimumLevel: minimumLevel, retainedFileCountLimit: null, //Setting to null means we keep all files - default is 31 days outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss,fff} [P{ProcessId}/D{AppDomainId}/T{ThreadId}] {Log4NetLevel} {SourceContext} - {Message:lj}{NewLine}{Exception}"); return(logConfig); }
public static LoggerConfiguration MinimalConfiguration( this LoggerConfiguration logConfig, Umbraco.Cms.Core.Hosting.IHostingEnvironment hostingEnvironment, ILoggingConfiguration loggingConfiguration, IConfiguration configuration, out UmbracoFileConfiguration umbFileConfiguration) { 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", hostingEnvironment.MapPathContentRoot("/").TrimEnd(Path.DirectorySeparatorChar), 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", hostingEnvironment.ApplicationId) // Updated later by ApplicationIdEnricher .Enrich.WithProperty("MachineName", Environment.MachineName) .Enrich.With <Log4NetLevelMapperEnricher>() .Enrich.FromLogContext(); // allows us to dynamically enrich //This is not optimal, but seems to be the only way if we do not make an Serilog.Sink.UmbracoFile sink all the way. var umbracoFileConfiguration = new UmbracoFileConfiguration(configuration); umbFileConfiguration = umbracoFileConfiguration; 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); }