diff --git a/src/Umbraco.Core/Logging/DebugDiagnosticsLogger.cs b/src/Umbraco.Core/Logging/DebugDiagnosticsLogger.cs
index b50c23d228..a8ca9b6c31 100644
--- a/src/Umbraco.Core/Logging/DebugDiagnosticsLogger.cs
+++ b/src/Umbraco.Core/Logging/DebugDiagnosticsLogger.cs
@@ -7,6 +7,36 @@ namespace Umbraco.Core.Logging
///
public class DebugDiagnosticsLogger : ILogger
{
+ ///
+ 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)
+ {
+ System.Diagnostics.Debug.WriteLine(Environment.NewLine + exception, reporting.FullName);
+ }
+
+ ///
+ public void Fatal(Type reporting, string message)
+ {
+ System.Diagnostics.Debug.WriteLine(message);
+ }
+
+ ///
+ 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);
+ }
+
+ ///
+ public void Fatal(Type reporting, string messageTemplate, params object[] args)
+ {
+ System.Diagnostics.Debug.WriteLine(messageTemplate, args);
+ }
+
///
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);
- }
+
}
}
diff --git a/src/Umbraco.Core/Logging/DisposableTimer.cs b/src/Umbraco.Core/Logging/DisposableTimer.cs
index e1e9d29c5f..869ca2cd44 100644
--- a/src/Umbraco.Core/Logging/DisposableTimer.cs
+++ b/src/Umbraco.Core/Logging/DisposableTimer.cs
@@ -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)
{
diff --git a/src/Umbraco.Core/Logging/ILogger.cs b/src/Umbraco.Core/Logging/ILogger.cs
index 643ad044a3..ec6d8edf31 100644
--- a/src/Umbraco.Core/Logging/ILogger.cs
+++ b/src/Umbraco.Core/Logging/ILogger.cs
@@ -7,6 +7,45 @@ namespace Umbraco.Core.Logging
///
public interface ILogger
{
+ ///
+ /// Logs a fatal message.
+ ///
+ /// The reporting type.
+ /// An exception.
+ /// A message.
+ void Fatal(Type reporting, Exception exception, string message);
+
+ ///
+ /// Logs a fatal message NOTE: This will log an empty message string
+ ///
+ /// The reporting type.
+ /// An exception.
+ void Fatal(Type reporting, Exception exception);
+
+ ///
+ /// Logs a fatal message WITHOUT EX
+ ///
+ /// The reporting type.
+ /// A message.
+ void Fatal(Type reporting, string message);
+
+ ///
+ /// Logs a fatal message - using a structured log message
+ ///
+ /// The reporting type.
+ /// An exception.
+ /// The message template that includes property values
+ /// Property values to log & update in message template
+ void Fatal(Type reporting, Exception exception, string messageTemplate, params object[] propertyValues);
+
+ ///
+ /// Logs a fatal message WITHOUT EX - using a structured log message
+ ///
+ /// The reporting type.
+ /// The message template that includes property values
+ /// Property values to log & update in message template
+ void Fatal(Type reporting, string messageTemplate, params object[] propertyValues);
+
///
/// Logs an error message.
///
@@ -122,22 +161,6 @@ namespace Umbraco.Core.Logging
/// The message template that includes property values
/// Property values to log & update in message template
void Verbose(Type reporting, string messageTemplate, params object[] propertyValues);
-
- ///
- /// Logs a fatal message.
- ///
- /// The reporting type.
- /// An exception.
- /// A message.
- void Fatal(Type reporting, Exception exception, string message);
-
- ///
- /// Logs a fatal message - using a structured log message
- ///
- /// The reporting type.
- /// An exception.
- /// The message template that includes property values
- /// Property values to log & update in message template
- void Fatal(Type reporting, Exception exception, string messageTemplate, params object[] propertyValues);
+
}
}
diff --git a/src/Umbraco.Core/Logging/Logger.cs b/src/Umbraco.Core/Logging/Logger.cs
index 656de088a7..0a20022e93 100644
--- a/src/Umbraco.Core/Logging/Logger.cs
+++ b/src/Umbraco.Core/Logging/Logger.cs
@@ -49,6 +49,40 @@ namespace Umbraco.Core.Logging
return new Logger(loggerConfig);
}
+ ///
+ public void Fatal(Type reporting, Exception exception, string message)
+ {
+ Fatal(reporting, exception, message, null);
+ }
+
+ ///
+ public void Fatal(Type reporting, Exception exception)
+ {
+ Fatal(reporting, exception, string.Empty);
+ }
+
+ ///
+ public void Fatal(Type reporting, string message)
+ {
+ //Sometimes we need to throw an error without an ex
+ Fatal(reporting, null, message);
+ }
+
+ ///
+ public void Fatal(Type reporting, string messageTemplate, params object[] propertyValues)
+ {
+ //Log a structured message WITHOUT an ex
+ Fatal(reporting, null, messageTemplate, propertyValues);
+ }
+
+ ///
+ 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);
+ }
+
///
public void Error(Type reporting, Exception exception, string message)
{
@@ -77,6 +111,13 @@ namespace Umbraco.Core.Logging
///
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 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
///
public void Warn(Type reporting, string format)
{
- var logger = Log.Logger;
- logger?.Warning(format);
+ Warn(reporting, null, format);
}
///
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);
}
///
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