-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fd64c3b
commit 5278c86
Showing
10 changed files
with
180 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<!-- | ||
Dianoga Log Configuration | ||
--> | ||
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/"> | ||
<sitecore> | ||
<log4net> | ||
<appender name="DianogaFileAppender" type="log4net.Appender.SitecoreLogFileAppender, Sitecore.Logging"> | ||
<file value="$(dataFolder)/logs/Dianoga.log.{date}.txt"/> | ||
<appendToFile value="true"/> | ||
<layout type="log4net.Layout.PatternLayout"> | ||
<conversionPattern value="%4t %d{ABSOLUTE} %-5p %m%n"/> | ||
</layout> | ||
<encoding value="utf-8"/> | ||
</appender> | ||
<logger name="Dianoga" additivity="false"> | ||
<level value="INFO" /> | ||
<appender-ref ref="DianogaFileAppender"/> | ||
<!-- On Azure PaaS you may want to enable this for App Insights logging | ||
<appender-ref ref="AzureFallbackAppender" desc="AzureFallbackAppender" /> | ||
--> | ||
</logger> | ||
</log4net> | ||
</sitecore> | ||
</configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
using System; | ||
using log4net; | ||
using Sitecore; | ||
using Sitecore.Diagnostics; | ||
|
||
namespace Dianoga | ||
{ | ||
|
||
/// <summary> | ||
/// Dianoga Logger | ||
/// </summary> | ||
public static class DianogaLog | ||
{ | ||
/// <summary> | ||
/// The local logger instance. | ||
/// </summary> | ||
private static readonly ILog Log; | ||
|
||
/// <summary> | ||
/// Initializes static members of the <see cref="T:Dianoga.DianogaLog" /> class. | ||
/// </summary> | ||
static DianogaLog() | ||
{ | ||
Log = LogManager.GetLogger("Dianoga") ?? LoggerFactory.GetLogger(typeof(DianogaLog)); | ||
} | ||
|
||
/// <summary> | ||
/// Logs info message with context user name. | ||
/// </summary> | ||
/// <param name="message">The message.</param> | ||
public static void Audit(string message) | ||
{ | ||
Assert.ArgumentNotNull(message, "message"); | ||
Log.Info($"AUDIT ({Context.User.Name}) {message}"); | ||
} | ||
|
||
/// <summary> | ||
/// Logs error message. | ||
/// </summary> | ||
/// <param name="message">The message.</param> | ||
/// <param name="exception">The exception.</param> | ||
public static void Error(string message, Exception exception = null) | ||
{ | ||
Assert.IsNotNull(Log, "Logger implementation was not initialized"); | ||
if (exception == null) | ||
{ | ||
Log.Error(message); | ||
} | ||
else | ||
{ | ||
Log.Error(message, exception); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Logs information message. | ||
/// </summary> | ||
/// <param name="message">The message.</param> | ||
/// <param name="exception">The exception.</param> | ||
public static void Info(string message, Exception exception = null) | ||
{ | ||
Assert.IsNotNull(Log, "Logger implementation was not initialized"); | ||
if (exception == null) | ||
{ | ||
Log.Info(message); | ||
} | ||
else | ||
{ | ||
Log.Info(message, exception); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Logs warning message. | ||
/// </summary> | ||
/// <param name="message">The message.</param> | ||
/// <param name="exception">The exception.</param> | ||
public static void Warn(string message, Exception exception = null) | ||
{ | ||
Assert.IsNotNull(Log, "Logger implementation was not initialized"); | ||
if (exception == null) | ||
{ | ||
Log.Warn(message); | ||
} | ||
else | ||
{ | ||
Log.Warn(message, exception); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Logs fatal error message. | ||
/// </summary> | ||
/// <param name="message">The message.</param> | ||
/// <param name="exception">The exception.</param> | ||
public static void Fatal(string message, Exception exception = null) | ||
{ | ||
Assert.IsNotNull(Log, "Logger implementation was not initialized"); | ||
if (exception == null) | ||
{ | ||
Log.Fatal(message); | ||
} | ||
else | ||
{ | ||
Log.Fatal(message, exception); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Logs debug message. | ||
/// </summary> | ||
/// <param name="message">The message.</param> | ||
/// <param name="exception">The exception.</param> | ||
public static void Debug(string message, Exception exception = null) | ||
{ | ||
Assert.IsNotNull(Log, "Logger implementation was not initialized"); | ||
if (exception == null) | ||
{ | ||
Log.Debug(message); | ||
} | ||
else | ||
{ | ||
Log.Debug(message, exception); | ||
} | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters