* Cleanup obsoleted methods * Add a way to disable UmbracoFile default sink * Abstract LogViewService so only UmbracoFile sink related things are in the default interface implementation. * Abstract LogViewRepository so only UmbracoFile sink related things are in the default interface implementation. * Move GetGlobalLogLevelEventMinLevel to base * Removed unused internal class and obsoleted its base * Added missing XML header comments and resolved warnings in service and repository classes. * Made private method static. * Addressed issues raised in code review. * Expose repository from the service base class. * Restored further obsoleted code we can't remove yet. * Removed log viewer tests on removed class. We have integration tests for the new service. * Obsoleted ILogViewer interface. --------- Co-authored-by: Andy Butland <abutland73@gmail.com>
55 lines
2.2 KiB
C#
55 lines
2.2 KiB
C#
using Microsoft.Extensions.Configuration;
|
|
using Serilog;
|
|
using Serilog.Events;
|
|
using Umbraco.Cms.Core.Logging;
|
|
|
|
namespace Umbraco.Cms.Infrastructure.Logging.Serilog;
|
|
|
|
public class UmbracoFileConfiguration
|
|
{
|
|
public UmbracoFileConfiguration(IConfiguration configuration)
|
|
{
|
|
if (configuration == null)
|
|
{
|
|
throw new ArgumentNullException(nameof(configuration));
|
|
}
|
|
|
|
IConfigurationSection? appSettings = configuration.GetSection("Serilog:WriteTo");
|
|
IConfigurationSection? umbracoFileAppSettings =
|
|
appSettings.GetChildren().LastOrDefault(x => x.GetValue<string>("Name") == "UmbracoFile");
|
|
|
|
if (umbracoFileAppSettings is not null)
|
|
{
|
|
IConfigurationSection? args = umbracoFileAppSettings.GetSection("Args");
|
|
|
|
Enabled = args.GetValue(nameof(Enabled), Enabled);
|
|
RestrictedToMinimumLevel = args.GetValue(nameof(RestrictedToMinimumLevel), RestrictedToMinimumLevel);
|
|
FileSizeLimitBytes = args.GetValue(nameof(FileSizeLimitBytes), FileSizeLimitBytes);
|
|
RollingInterval = args.GetValue(nameof(RollingInterval), RollingInterval);
|
|
FlushToDiskInterval = args.GetValue(nameof(FlushToDiskInterval), FlushToDiskInterval);
|
|
RollOnFileSizeLimit = args.GetValue(nameof(RollOnFileSizeLimit), RollOnFileSizeLimit);
|
|
RetainedFileCountLimit = args.GetValue(nameof(RetainedFileCountLimit), RetainedFileCountLimit);
|
|
}
|
|
}
|
|
|
|
public bool Enabled { get; set; } = true;
|
|
|
|
public LogEventLevel RestrictedToMinimumLevel { get; set; } = LogEventLevel.Verbose;
|
|
|
|
public long FileSizeLimitBytes { get; set; } = 1073741824;
|
|
|
|
public RollingInterval RollingInterval { get; set; } = RollingInterval.Day;
|
|
|
|
public TimeSpan? FlushToDiskInterval { get; set; }
|
|
|
|
public bool RollOnFileSizeLimit { get; set; }
|
|
|
|
public int RetainedFileCountLimit { get; set; } = 31;
|
|
|
|
public string GetPath(string logDirectory) =>
|
|
GetPath(logDirectory, LoggingConfiguration.DefaultLogFileNameFormat, Environment.MachineName);
|
|
|
|
public string GetPath(string logDirectory, string fileNameFormat, params string[] fileNameArgs) =>
|
|
Path.Combine(logDirectory, string.Format(fileNameFormat, fileNameArgs));
|
|
}
|