Merge branch 'temp8-serilog' into temp8-logviewer
This commit is contained in:
@@ -7,6 +7,36 @@ namespace Umbraco.Core.Logging
|
||||
/// </summary>
|
||||
public class DebugDiagnosticsLogger : ILogger
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
public void Fatal(Type reporting, Exception exception, string message)
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine(message + Environment.NewLine + exception, reporting.FullName);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Fatal(Type reporting, Exception exception)
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine(Environment.NewLine + exception, reporting.FullName);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Fatal(Type reporting, string message)
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine(message);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Fatal(Type reporting, Exception exception, string messageTemplate, params object[] args)
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine(string.Format(messageTemplate, args) + Environment.NewLine + exception, reporting.FullName);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Fatal(Type reporting, string messageTemplate, params object[] args)
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine(messageTemplate, args);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Error(Type reporting, Exception exception, string message)
|
||||
{
|
||||
@@ -96,15 +126,6 @@ namespace Umbraco.Core.Logging
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine(string.Format(format, args), reporting.FullName);
|
||||
}
|
||||
|
||||
public void Fatal(Type reporting, Exception exception, string message)
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine(message + Environment.NewLine + exception, reporting.FullName);
|
||||
}
|
||||
|
||||
public void Fatal(Type reporting, Exception exception, string messageTemplate, params object[] args)
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine(string.Format(messageTemplate, args) + Environment.NewLine + exception, reporting.FullName);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace Umbraco.Core.Logging
|
||||
private string _failMessage;
|
||||
private Exception _failException;
|
||||
private bool _failed;
|
||||
private Guid _timingId;
|
||||
private readonly string _timingId;
|
||||
|
||||
internal enum LogType
|
||||
{
|
||||
@@ -38,7 +38,7 @@ namespace Umbraco.Core.Logging
|
||||
_endMessage = endMessage;
|
||||
_failMessage = failMessage;
|
||||
_thresholdMilliseconds = thresholdMilliseconds < 0 ? 0 : thresholdMilliseconds;
|
||||
_timingId = Guid.NewGuid();
|
||||
_timingId = Guid.NewGuid().ToString("N");
|
||||
|
||||
if (thresholdMilliseconds == 0)
|
||||
{
|
||||
|
||||
@@ -7,6 +7,45 @@ namespace Umbraco.Core.Logging
|
||||
/// </summary>
|
||||
public interface ILogger
|
||||
{
|
||||
/// <summary>
|
||||
/// Logs a fatal message.
|
||||
/// </summary>
|
||||
/// <param name="reporting">The reporting type.</param>
|
||||
/// <param name="exception">An exception.</param>
|
||||
/// <param name="message">A message.</param>
|
||||
void Fatal(Type reporting, Exception exception, string message);
|
||||
|
||||
/// <summary>
|
||||
/// Logs a fatal message NOTE: This will log an empty message string
|
||||
/// </summary>
|
||||
/// <param name="reporting">The reporting type.</param>
|
||||
/// <param name="exception">An exception.</param>
|
||||
void Fatal(Type reporting, Exception exception);
|
||||
|
||||
/// <summary>
|
||||
/// Logs a fatal message WITHOUT EX
|
||||
/// </summary>
|
||||
/// <param name="reporting">The reporting type.</param>
|
||||
/// <param name="message">A message.</param>
|
||||
void Fatal(Type reporting, string message);
|
||||
|
||||
/// <summary>
|
||||
/// Logs a fatal message - using a structured log message
|
||||
/// </summary>
|
||||
/// <param name="reporting">The reporting type.</param>
|
||||
/// <param name="exception">An exception.</param>
|
||||
/// <param name="messageTemplate">The message template that includes property values</param>
|
||||
/// <param name="propertyValues">Property values to log & update in message template</param>
|
||||
void Fatal(Type reporting, Exception exception, string messageTemplate, params object[] propertyValues);
|
||||
|
||||
/// <summary>
|
||||
/// Logs a fatal message WITHOUT EX - using a structured log message
|
||||
/// </summary>
|
||||
/// <param name="reporting">The reporting type.</param>
|
||||
/// <param name="messageTemplate">The message template that includes property values</param>
|
||||
/// <param name="propertyValues">Property values to log & update in message template</param>
|
||||
void Fatal(Type reporting, string messageTemplate, params object[] propertyValues);
|
||||
|
||||
/// <summary>
|
||||
/// Logs an error message.
|
||||
/// </summary>
|
||||
@@ -122,22 +161,6 @@ namespace Umbraco.Core.Logging
|
||||
/// <param name="messageTemplate">The message template that includes property values</param>
|
||||
/// <param name="propertyValues">Property values to log & update in message template</param>
|
||||
void Verbose(Type reporting, string messageTemplate, params object[] propertyValues);
|
||||
|
||||
/// <summary>
|
||||
/// Logs a fatal message.
|
||||
/// </summary>
|
||||
/// <param name="reporting">The reporting type.</param>
|
||||
/// <param name="exception">An exception.</param>
|
||||
/// <param name="message">A message.</param>
|
||||
void Fatal(Type reporting, Exception exception, string message);
|
||||
|
||||
/// <summary>
|
||||
/// Logs a fatal message - using a structured log message
|
||||
/// </summary>
|
||||
/// <param name="reporting">The reporting type.</param>
|
||||
/// <param name = "exception" > An exception.</param>
|
||||
/// <param name="messageTemplate">The message template that includes property values</param>
|
||||
/// <param name="propertyValues">Property values to log & update in message template</param>
|
||||
void Fatal(Type reporting, Exception exception, string messageTemplate, params object[] propertyValues);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,6 +49,40 @@ namespace Umbraco.Core.Logging
|
||||
return new Logger(loggerConfig);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Fatal(Type reporting, Exception exception, string message)
|
||||
{
|
||||
Fatal(reporting, exception, message, null);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Fatal(Type reporting, Exception exception)
|
||||
{
|
||||
Fatal(reporting, exception, string.Empty);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Fatal(Type reporting, string message)
|
||||
{
|
||||
//Sometimes we need to throw an error without an ex
|
||||
Fatal(reporting, null, message);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Fatal(Type reporting, string messageTemplate, params object[] propertyValues)
|
||||
{
|
||||
//Log a structured message WITHOUT an ex
|
||||
Fatal(reporting, null, messageTemplate, propertyValues);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Fatal(Type reporting, Exception exception, string messageTemplate, params object[] propertyValues)
|
||||
{
|
||||
ErrorOrFatal(Fatal, exception, ref messageTemplate);
|
||||
var logger = Log.Logger;
|
||||
logger?.ForContext(reporting).Fatal(exception, messageTemplate, propertyValues);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Error(Type reporting, Exception exception, string message)
|
||||
{
|
||||
@@ -77,6 +111,13 @@ namespace Umbraco.Core.Logging
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Error(Type reporting, Exception exception, string messageTemplate, params object[] propertyValues)
|
||||
{
|
||||
ErrorOrFatal(Error, exception, ref messageTemplate);
|
||||
var logger = Log.Logger;
|
||||
logger?.ForContext(reporting).Error(exception, messageTemplate, propertyValues);
|
||||
}
|
||||
|
||||
private static void ErrorOrFatal(Action<Type, Exception, string, object[]> logAction, Exception exception, ref string messageTemplate)
|
||||
{
|
||||
var dump = false;
|
||||
|
||||
@@ -103,18 +144,15 @@ namespace Umbraco.Core.Logging
|
||||
catch (Exception ex)
|
||||
{
|
||||
//Log a new entry (as opposed to appending to same log entry)
|
||||
Error(ex.GetType(), ex, "Failed to create a minidump at App_Data/MiniDump ({ExType}: {ExMessage}", ex.GetType().FullName, ex.Message);
|
||||
logAction(ex.GetType(), ex, "Failed to create a minidump at App_Data/MiniDump ({ExType}: {ExMessage}",
|
||||
new object[]{ ex.GetType().FullName, ex.Message });
|
||||
}
|
||||
}
|
||||
|
||||
var logger = Log.Logger;
|
||||
logger?.ForContext(reporting).Error(exception, messageTemplate, propertyValues);
|
||||
}
|
||||
|
||||
private static bool IsMonitorEnterThreadAbortException(Exception exception)
|
||||
{
|
||||
var abort = exception as ThreadAbortException;
|
||||
if (abort == null) return false;
|
||||
if (!(exception is ThreadAbortException abort)) return false;
|
||||
|
||||
var stacktrace = abort.StackTrace;
|
||||
return stacktrace.Contains("System.Threading.Monitor.ReliableEnter");
|
||||
@@ -122,8 +160,7 @@ namespace Umbraco.Core.Logging
|
||||
|
||||
private static bool IsTimeoutThreadAbortException(Exception exception)
|
||||
{
|
||||
var abort = exception as ThreadAbortException;
|
||||
if (abort == null) return false;
|
||||
if (!(exception is ThreadAbortException abort)) return false;
|
||||
|
||||
if (abort.ExceptionState == null) return false;
|
||||
|
||||
@@ -139,22 +176,19 @@ namespace Umbraco.Core.Logging
|
||||
/// <inheritdoc/>
|
||||
public void Warn(Type reporting, string format)
|
||||
{
|
||||
var logger = Log.Logger;
|
||||
logger?.Warning(format);
|
||||
Warn(reporting, null, format);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Warn(Type reporting, string messageTemplate, params object[] propertyValues)
|
||||
{
|
||||
var logger = Log.Logger;
|
||||
logger?.ForContext(reporting).Warning(messageTemplate, propertyValues);
|
||||
Warn(reporting, null, messageTemplate, propertyValues);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Warn(Type reporting, Exception exception, string message)
|
||||
{
|
||||
var logger = Log.Logger;
|
||||
logger?.ForContext(reporting).Warning(message, exception);
|
||||
Warn(reporting, exception, message, Array.Empty<object>());
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
@@ -167,8 +201,7 @@ namespace Umbraco.Core.Logging
|
||||
/// <inheritdoc/>
|
||||
public void Info(Type reporting, string message)
|
||||
{
|
||||
var logger = Log.Logger;
|
||||
logger?.ForContext(reporting).Information(message);
|
||||
Info(reporting, message, Array.Empty<object>());
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
@@ -181,8 +214,7 @@ namespace Umbraco.Core.Logging
|
||||
/// <inheritdoc/>
|
||||
public void Debug(Type reporting, string message)
|
||||
{
|
||||
var logger = Log.Logger;
|
||||
logger?.ForContext(reporting).Debug(message);
|
||||
Debug(reporting, message, Array.Empty<object>());
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
@@ -195,8 +227,7 @@ namespace Umbraco.Core.Logging
|
||||
/// <inheritdoc/>
|
||||
public void Verbose(Type reporting, string message)
|
||||
{
|
||||
var logger = Log.Logger;
|
||||
logger?.ForContext(reporting).Verbose(message);
|
||||
Verbose(reporting, message, Array.Empty<object>());
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
@@ -206,18 +237,6 @@ namespace Umbraco.Core.Logging
|
||||
logger?.ForContext(reporting).Verbose(messageTemplate, propertyValues);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Fatal(Type reporting, Exception exception, string message)
|
||||
{
|
||||
var logger = Log.Logger;
|
||||
logger?.ForContext(reporting).Fatal(exception, message);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Fatal(Type reporting, Exception exception, string messageTemplate, params object[] propertyValues)
|
||||
{
|
||||
var logger = Log.Logger;
|
||||
logger?.ForContext(reporting).Fatal(exception, messageTemplate, propertyValues);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,6 +45,7 @@ namespace Umbraco.Core.Logging.SerilogExtensions
|
||||
//Main .txt logfile - in similar format to older Log4Net output
|
||||
//Ends with ..txt as Date is inserted before file extension substring
|
||||
logConfig.WriteTo.File($@"{AppDomain.CurrentDomain.BaseDirectory}\App_Data\Logs\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
|
||||
@@ -64,6 +65,7 @@ namespace Umbraco.Core.Logging.SerilogExtensions
|
||||
//.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(), $@"{AppDomain.CurrentDomain.BaseDirectory}\App_Data\Logs\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);
|
||||
|
||||
@@ -5,6 +5,34 @@ namespace Umbraco.Tests.TestHelpers
|
||||
{
|
||||
public class ConsoleLogger : ILogger
|
||||
{
|
||||
public void Fatal(Type reporting, Exception exception, string message)
|
||||
{
|
||||
Console.WriteLine("FATAL {0} - {1}", reporting.Name, message);
|
||||
Console.WriteLine(exception);
|
||||
}
|
||||
|
||||
public void Fatal(Type reporting, Exception exception)
|
||||
{
|
||||
Console.WriteLine("FATAL {0}", reporting.Name);
|
||||
Console.WriteLine(exception);
|
||||
}
|
||||
|
||||
public void Fatal(Type reporting, string message)
|
||||
{
|
||||
Console.WriteLine("FATAL {0} - {1}", reporting.Name, message);
|
||||
}
|
||||
|
||||
public void Fatal(Type reporting, Exception exception, string format, params object[] args)
|
||||
{
|
||||
Console.WriteLine("FATAL {0} - {1}", reporting.Name, string.Format(format, args));
|
||||
Console.WriteLine(exception);
|
||||
}
|
||||
|
||||
public void Fatal(Type reporting, string format, params object[] args)
|
||||
{
|
||||
Console.WriteLine("FATAL {0} - {1}", reporting.Name, string.Format(format, args));
|
||||
}
|
||||
|
||||
public void Error(Type reporting, Exception exception, string message)
|
||||
{
|
||||
Console.WriteLine("ERROR {0} - {1}", reporting.Name, message);
|
||||
@@ -84,17 +112,5 @@ namespace Umbraco.Tests.TestHelpers
|
||||
{
|
||||
Console.WriteLine("VERBOSE {0} - {1}", reporting.Name, string.Format(format, args));
|
||||
}
|
||||
|
||||
public void Fatal(Type reporting, Exception exception, string message)
|
||||
{
|
||||
Console.WriteLine("FATAL {0} - {1}", reporting.Name, message);
|
||||
Console.WriteLine(exception);
|
||||
}
|
||||
|
||||
public void Fatal(Type reporting, Exception exception, string format, params object[] args)
|
||||
{
|
||||
Console.WriteLine("FATAL {0} - {1}", reporting.Name, string.Format(format, args));
|
||||
Console.WriteLine(exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -167,7 +167,7 @@ namespace Umbraco.Tests.Testing
|
||||
}
|
||||
else if (option == UmbracoTestOptions.Logger.Serilog)
|
||||
{
|
||||
Container.RegisterSingleton<ILogger>(f => new Logger(new FileInfo(TestHelper.MapPathForTest("~/unit-test-log4net.config"))));
|
||||
Container.RegisterSingleton<ILogger>(f => new Logger(new FileInfo(TestHelper.MapPathForTest("~/unit-test.config"))));
|
||||
Container.RegisterSingleton<IProfiler>(f => new LogProfiler(f.GetInstance<ILogger>()));
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace Umbraco.Tests.UmbracoExamine
|
||||
[OneTimeSetUp]
|
||||
public void InitializeFixture()
|
||||
{
|
||||
var logger = new Logger(new FileInfo(TestHelper.MapPathForTest("~/unit-test-log4net.config")));
|
||||
var logger = new Logger(new FileInfo(TestHelper.MapPathForTest("~/unit-test.config")));
|
||||
_profilingLogger = new ProfilingLogger(logger, new LogProfiler(logger));
|
||||
}
|
||||
|
||||
|
||||
@@ -2,28 +2,36 @@
|
||||
<configuration>
|
||||
<appSettings>
|
||||
|
||||
<!-- Controls log levels for all user-definied child sub-logger sinks configured here (Set this higher than child sinks) -->
|
||||
<!-- Controls log levels for all user-defined child sub-logger sinks configured here (Set this higher than child sinks defined here) -->
|
||||
<add key="serilog:minimum-level" value="Verbose" />
|
||||
|
||||
<!-- For Different Namespaces - Set different logging levels -->
|
||||
<!--
|
||||
<add key="serilog:minimum-level:override:Microsoft" value="Warning" />
|
||||
<add key="serilog:minimum-level:override:Microsoft.AspNetCore.Mvc" value="Error" />
|
||||
<add key="serilog:minimum-level:override:YourNameSpace" value="Information" />
|
||||
-->
|
||||
|
||||
<!-- All logs definied via user.config will contain this property (won't be in main Umbraco logs) -->
|
||||
<add key="serilog:enrich:with-property:websiteName" value="Warrens Website" />
|
||||
<!-- All logs defined via user.config will contain this property (won't be in main Umbraco logs) -->
|
||||
<!--
|
||||
<add key="serilog:enrich:with-property:websiteName" value="My Awesome Website - Development" />
|
||||
-->
|
||||
|
||||
<!-- Write to a user log file -->
|
||||
<!--
|
||||
<add key="serilog:using:File" value="Serilog.Sinks.File" />
|
||||
<add key="serilog:write-to:File.path" value="%BASEDIR%\logs\warren-log.txt" />
|
||||
<add key="serilog:write-to:File.restrictedToMinimumLevel" value="Debug" /> <!-- I will be ignored as Debug as the user logging pipleine has it min set to Information, so only Info will flow through me -->
|
||||
<add key="serilog:write-to:File.retainedFileCountLimit" value="32" /> <!-- Number of log files to keep (or remove value to keep all files) -->
|
||||
<add key="serilog:write-to:File.rollingInterval" value="Day" /> <!-- Create a new log file every Minute/Hour/Day/Month/Year/infinite -->
|
||||
<add key="serilog:write-to:File.path" value="%BASEDIR%\logs\my-custom-logfile.txt" />
|
||||
<add key="serilog:write-to:File.shared" value="true" />
|
||||
<add key="serilog:write-to:File.restrictedToMinimumLevel" value="Debug" />
|
||||
<add key="serilog:write-to:File.retainedFileCountLimit" value="32" />--> <!-- Number of log files to keep (or remove value to keep all files) -->
|
||||
<!--<add key="serilog:write-to:File.rollingInterval" value="Day" />--> <!-- Create a new log file every Minute/Hour/Day/Month/Year/infinite -->
|
||||
|
||||
<!-- Filters all above sink's to use this expression -->
|
||||
<!-- Common use case is to include SourceType starting with your own namespace -->
|
||||
<!--
|
||||
<add key="serilog:using:FilterExpressions" value="Serilog.Filters.Expressions" />
|
||||
<add key="serilog:filter:ByIncluding.expression" value="StartsWith(SourceContext, 'Umbraco.Core')" />
|
||||
-->
|
||||
|
||||
</appSettings>
|
||||
</configuration>
|
||||
|
||||
Reference in New Issue
Block a user