Change GetAbsoluteLoggingPath to extension method
This commit is contained in:
33
src/Umbraco.Core/Configuration/LoggingSettingsExtensions.cs
Normal file
33
src/Umbraco.Core/Configuration/LoggingSettingsExtensions.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
// Copyright (c) Umbraco.
|
||||
// See LICENSE for more details.
|
||||
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Umbraco.Cms.Core.Configuration.Models;
|
||||
using Umbraco.Cms.Core.Extensions;
|
||||
|
||||
namespace Umbraco.Extensions;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for <see cref="LoggingSettings" />.
|
||||
/// </summary>
|
||||
public static class LoggingSettingsExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the absolute logging path (maps a virtual path to the applications content root).
|
||||
/// </summary>
|
||||
/// <param name="loggingSettings">The logging settings.</param>
|
||||
/// <param name="hostEnvironment">The host environment.</param>
|
||||
/// <returns>
|
||||
/// The absolute logging path.
|
||||
/// </returns>
|
||||
public static string GetAbsoluteLoggingPath(this LoggingSettings loggingSettings, IHostEnvironment hostEnvironment)
|
||||
{
|
||||
var dir = loggingSettings.Directory;
|
||||
if (dir.StartsWith("~/"))
|
||||
{
|
||||
return hostEnvironment.MapPathContentRoot(dir);
|
||||
}
|
||||
|
||||
return dir;
|
||||
}
|
||||
}
|
||||
@@ -2,13 +2,11 @@
|
||||
// See LICENSE for more details.
|
||||
|
||||
using System.ComponentModel;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Umbraco.Cms.Core.Extensions;
|
||||
|
||||
namespace Umbraco.Cms.Core.Configuration.Models;
|
||||
|
||||
/// <summary>
|
||||
/// Typed configuration options for logging settings.
|
||||
/// Typed configuration options for logging settings.
|
||||
/// </summary>
|
||||
[UmbracoOptions(Constants.Configuration.ConfigLogging)]
|
||||
public class LoggingSettings
|
||||
@@ -17,25 +15,20 @@ public class LoggingSettings
|
||||
internal const string StaticDirectory = Constants.SystemDirectories.LogFiles;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value for the maximum age of a log file.
|
||||
/// Gets or sets a value for the maximum age of a log file.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The maximum log age.
|
||||
/// </value>
|
||||
[DefaultValue(StaticMaxLogAge)]
|
||||
public TimeSpan MaxLogAge { get; set; } = TimeSpan.Parse(StaticMaxLogAge);
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the folder to use for log files
|
||||
/// Gets or sets the folder to use for log files.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The directory.
|
||||
/// </value>
|
||||
[DefaultValue(StaticDirectory)]
|
||||
public string Directory { get; set; } = StaticDirectory;
|
||||
|
||||
public string GetAbsoluteLoggingPath(IHostEnvironment hostEnvironment)
|
||||
{
|
||||
var dir = Directory;
|
||||
if (dir.StartsWith("~/"))
|
||||
{
|
||||
return hostEnvironment.MapPathContentRoot(dir);
|
||||
}
|
||||
|
||||
return dir;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user