Merge branch 'v11/dev' into v11/contrib
This commit is contained in:
@@ -7,6 +7,7 @@ using Serilog.Core;
|
||||
using Serilog.Events;
|
||||
using Serilog.Formatting;
|
||||
using Serilog.Formatting.Compact;
|
||||
using Umbraco.Cms.Core.Configuration.Models;
|
||||
using Umbraco.Cms.Core.Extensions;
|
||||
using Umbraco.Cms.Core.Logging;
|
||||
using Umbraco.Cms.Core.Logging.Serilog.Enrichers;
|
||||
@@ -21,7 +22,7 @@ namespace Umbraco.Extensions
|
||||
/// Such as adding ProcessID, Thread, AppDomain etc
|
||||
/// It is highly recommended that you keep/use this default in your own logging config customizations
|
||||
/// </summary>
|
||||
[Obsolete("Please use an alternative method.")]
|
||||
[Obsolete("Please use an alternative method. This will be removed in Umbraco 13.")]
|
||||
public static LoggerConfiguration MinimalConfiguration(
|
||||
this LoggerConfiguration logConfig,
|
||||
Umbraco.Cms.Core.Hosting.IHostingEnvironment hostingEnvironment,
|
||||
@@ -36,7 +37,7 @@ namespace Umbraco.Extensions
|
||||
/// Such as adding ProcessID, Thread, AppDomain etc
|
||||
/// It is highly recommended that you keep/use this default in your own logging config customizations
|
||||
/// </summary>
|
||||
[Obsolete("Please use an alternative method.")]
|
||||
[Obsolete("Please use an alternative method. This will be removed in Umbraco 13.")]
|
||||
public static LoggerConfiguration MinimalConfiguration(
|
||||
this LoggerConfiguration logConfig,
|
||||
Umbraco.Cms.Core.Hosting.IHostingEnvironment hostingEnvironment,
|
||||
@@ -126,6 +127,7 @@ namespace Umbraco.Extensions
|
||||
/// <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>
|
||||
[Obsolete("Will be removed in Umbraco 13.")]
|
||||
public static LoggerConfiguration OutputDefaultTextFile(
|
||||
this LoggerConfiguration logConfig,
|
||||
Umbraco.Cms.Core.Hosting.IHostingEnvironment hostingEnvironment,
|
||||
@@ -144,6 +146,31 @@ namespace Umbraco.Extensions
|
||||
return logConfig;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Outputs a .txt format log at /App_Data/Logs/
|
||||
/// </summary>
|
||||
/// <param name="logConfig">A Serilog LoggerConfiguration</param>
|
||||
/// <param name="hostEnvironment"></param>
|
||||
/// <param name="loggingSettings"></param>
|
||||
/// <param name="minimumLevel">The log level you wish the JSON file to collect - default is Verbose (highest)</param>
|
||||
public static LoggerConfiguration OutputDefaultTextFile(
|
||||
this LoggerConfiguration logConfig,
|
||||
IHostEnvironment hostEnvironment,
|
||||
LoggingSettings loggingSettings,
|
||||
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(loggingSettings.GetAbsoluteLoggingPath(hostEnvironment), $"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;
|
||||
}
|
||||
|
||||
/// <remarks>
|
||||
/// Used in config - If renamed or moved to other assembly the config file also has be updated.
|
||||
@@ -195,6 +222,7 @@ namespace Umbraco.Extensions
|
||||
/// <param name="minimumLevel">The log level you wish the JSON file to collect - default is Verbose (highest)</param>
|
||||
/// <param name="hostingEnvironment"></param>
|
||||
/// <param name="retainedFileCount">The number of days to keep log files. Default is set to null which means all logs are kept</param>
|
||||
[Obsolete("Will be removed in Umbraco 13.")]
|
||||
public static LoggerConfiguration OutputDefaultJsonFile(
|
||||
this LoggerConfiguration logConfig,
|
||||
Umbraco.Cms.Core.Hosting.IHostingEnvironment hostingEnvironment,
|
||||
@@ -215,5 +243,33 @@ namespace Umbraco.Extensions
|
||||
return logConfig;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Outputs a CLEF format JSON log at /App_Data/Logs/
|
||||
/// </summary>
|
||||
/// <param name="logConfig">A Serilog LoggerConfiguration</param>
|
||||
/// <param name="hostEnvironment"></param>
|
||||
/// <param name="loggingSettings">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,
|
||||
IHostEnvironment hostEnvironment,
|
||||
LoggingSettings loggingSettings,
|
||||
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(loggingSettings.GetAbsoluteLoggingPath(hostEnvironment) ,$"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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user