Refactor logging
This commit is contained in:
1 parent
b930588556
commit
c907ec0f44
67 files changed
+2039
-627
No files matched your search
@@ -0,0 +1,79 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using Serilog;
|
||||
using VocaluxeLib.Log.Enricher;
|
||||
using VocaluxeLib.Log.Rolling;
|
||||
using VocaluxeLib.Log.Serilog;
|
||||
|
||||
namespace VocaluxeLib.Log
|
||||
{
|
||||
public static partial class CLog
|
||||
{
|
||||
private static readonly StringBuilder _MainLogStringBuilder = new StringBuilder();
|
||||
private static readonly StringWriter _MainLogStringWriter = new StringWriter(_MainLogStringBuilder);
|
||||
|
||||
private static ILogger _MainLog = new SilentLogger();
|
||||
private static ILogger _SongLog = new SilentLogger();
|
||||
private static string _LogFolder;
|
||||
|
||||
private const string _MainLogTemplate = "[{TimeStampFromStart}] [{Level}] {Message}{NewLine}{Properties}{NewLine}{Exception}";
|
||||
private const string _SongLogTemplate = "{Message}{NewLine}Additional info:{Properties}{NewLine}{Exception}";
|
||||
|
||||
public static void Init(string logFolder, string fileNameMainLog, string fileNameSongInfoLog)
|
||||
{
|
||||
_LogFolder = logFolder;
|
||||
if (!Directory.Exists(_LogFolder))
|
||||
Directory.CreateDirectory(_LogFolder);
|
||||
|
||||
LogFileRoller.RollLogs(Path.Combine(_LogFolder, fileNameMainLog), 2);
|
||||
LogFileRoller.RollLogs(Path.Combine(_LogFolder, fileNameSongInfoLog), 2);
|
||||
|
||||
_MainLog = new LoggerConfiguration()
|
||||
.Enrich.WithThreadId()
|
||||
.Enrich.FromLogContext()
|
||||
.Enrich.WithTimeStampFromStart()
|
||||
.WriteTo.TextWriter(_MainLogStringWriter, outputTemplate: _MainLogTemplate)
|
||||
// Json can be activated by adding "new CompactJsonFormatter()" as first argument
|
||||
.WriteTo.File(Path.Combine(_LogFolder, fileNameMainLog), flushToDiskInterval: TimeSpan.FromSeconds(30), outputTemplate: _MainLogTemplate)
|
||||
#if DEBUG
|
||||
.WriteTo.Console(outputTemplate: _MainLogTemplate)
|
||||
#endif
|
||||
.CreateLogger();
|
||||
|
||||
_SongLog = new LoggerConfiguration()
|
||||
.WriteTo.File(Path.Combine(_LogFolder, fileNameSongInfoLog), flushToDiskInterval: TimeSpan.FromSeconds(60), outputTemplate: _SongLogTemplate)
|
||||
#if DEBUG
|
||||
.WriteTo.Console(outputTemplate: "[SongInfo] " + _SongLogTemplate)
|
||||
#endif
|
||||
.CreateLogger();
|
||||
}
|
||||
|
||||
public static void Close()
|
||||
{
|
||||
if (!(_MainLog is SilentLogger))
|
||||
{
|
||||
ILogger loggerToDispose = _MainLog;
|
||||
|
||||
_MainLog = new SilentLogger();
|
||||
(_MainLog as IDisposable)?.Dispose();
|
||||
}
|
||||
|
||||
if (!(_SongLog is SilentLogger))
|
||||
{
|
||||
ILogger loggerToDispose = _MainLog;
|
||||
|
||||
_SongLog = new SilentLogger();
|
||||
(_SongLog as IDisposable)?.Dispose();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static void _ShowLogAssistent(string messageTemplate, object[] propertyValues, string callerMethodeName = "", string callerFilePath = "", int callerLineNumer = -1)
|
||||
{
|
||||
//Todo: Logsend assistent
|
||||
//MessageBox.Show(messageTemplate, "Vocaluxe", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,959 @@
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Runtime.CompilerServices;
|
||||
using Serilog.Context;
|
||||
using Serilog.Core;
|
||||
|
||||
namespace VocaluxeLib.Log
|
||||
{
|
||||
public static partial class CLog
|
||||
{
|
||||
|
||||
public static object[] Params(params object[] propertyValues)
|
||||
{
|
||||
return propertyValues;
|
||||
}
|
||||
|
||||
|
||||
#region Verbose functions
|
||||
|
||||
/// <summary>
|
||||
/// Write an event with the Verbose level to the Verbose log.
|
||||
/// </summary>
|
||||
/// <param name="messageTemplate">Message template for this event.</param>
|
||||
/// <param name="show">True if an message should be shown to the user, false otherwise.</param>
|
||||
/// <param name="callerMethodeName">Don't use! The methode name of the caller will be filled automatically by the compiler.</param>
|
||||
/// <param name="callerFilePath">Don't use! The filepath of the caller will be filled automatically by the compiler.</param>
|
||||
/// <param name="callerLineNumer">Don't use! The line number of the caller will be filled automatically by the compiler.</param>
|
||||
[MessageTemplateFormatMethod("messageTemplate")]
|
||||
public static void Verbose(string messageTemplate, bool show = false, [CallerMemberName] string callerMethodeName = "", [CallerFilePath] string callerFilePath = "", [CallerLineNumber] int callerLineNumer = -1)
|
||||
{
|
||||
using (LogContext.PushProperty("CallingContext", new { callerMethodeName, callerFilePath, callerLineNumer}))
|
||||
{
|
||||
_MainLog.Verbose(messageTemplate);
|
||||
}
|
||||
if(show)
|
||||
_ShowLogAssistent(messageTemplate, null, callerMethodeName, callerFilePath, callerLineNumer);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write an event with the Verbose level with additional propertyValues to the Verbose log.
|
||||
/// </summary>
|
||||
/// <param name="messageTemplate">Message template for this event.</param>
|
||||
/// <param name="propertyValues">Data inserted into the message template.</param>
|
||||
/// <param name="show">True if an message should be shown to the user, false otherwise.</param>
|
||||
/// <param name="callerMethodeName">Don't use! The methode name of the caller will be filled automatically by the compiler.</param>
|
||||
/// <param name="callerFilePath">Don't use! The filepath of the caller will be filled automatically by the compiler.</param>
|
||||
/// <param name="callerLineNumer">Don't use! The line number of the caller will be filled automatically by the compiler.</param>
|
||||
[MessageTemplateFormatMethod("messageTemplate")]
|
||||
public static void Verbose(string messageTemplate, object[] propertyValues, bool show = false, [CallerMemberName] string callerMethodeName = "", [CallerFilePath] string callerFilePath = "", [CallerLineNumber] int callerLineNumer = -1)
|
||||
{
|
||||
using (LogContext.PushProperty("CallingContext", new { callerMethodeName, callerFilePath, callerLineNumer}))
|
||||
{
|
||||
_MainLog.Verbose(messageTemplate, propertyValues);
|
||||
}
|
||||
if(show)
|
||||
_ShowLogAssistent(messageTemplate, propertyValues, callerMethodeName, callerFilePath, callerLineNumer);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write an event with the Verbose level and associated exception to the Verbose log.
|
||||
/// </summary>
|
||||
/// <param name="exception">Exception of this event.</param>
|
||||
/// <param name="messageTemplate">Message template for this event.</param>
|
||||
/// <param name="show">True if an message should be shown to the user, false otherwise.</param>
|
||||
/// <param name="callerMethodeName">Don't use! The methode name of the caller will be filled automatically by the compiler.</param>
|
||||
/// <param name="callerFilePath">Don't use! The filepath of the caller will be filled automatically by the compiler.</param>
|
||||
/// <param name="callerLineNumer">Don't use! The line number of the caller will be filled automatically by the compiler.</param>
|
||||
[MessageTemplateFormatMethod("messageTemplate")]
|
||||
public static void Verbose(Exception exception, string messageTemplate, bool show = false, [CallerMemberName] string callerMethodeName = "", [CallerFilePath] string callerFilePath = "", [CallerLineNumber] int callerLineNumer = -1)
|
||||
{
|
||||
using (LogContext.PushProperty("CallingContext", new { callerMethodeName, callerFilePath, callerLineNumer}))
|
||||
{
|
||||
_MainLog.Verbose( exception, messageTemplate);
|
||||
}
|
||||
if(show)
|
||||
_ShowLogAssistent(messageTemplate, null, callerMethodeName, callerFilePath, callerLineNumer);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write an event with the Verbose level with additional propertyValues and associated exception to the Verbose log.
|
||||
/// </summary>
|
||||
/// <param name="exception">Exception of this event.</param>
|
||||
/// <param name="messageTemplate">Message template for this event.</param>
|
||||
/// <param name="propertyValues">Data inserted into the message template.</param>
|
||||
/// <param name="show">True if an message should be shown to the user, false otherwise.</param>
|
||||
/// <param name="callerMethodeName">Don't use! The methode name of the caller will be filled automatically by the compiler.</param>
|
||||
/// <param name="callerFilePath">Don't use! The filepath of the caller will be filled automatically by the compiler.</param>
|
||||
/// <param name="callerLineNumer">Don't use! The line number of the caller will be filled automatically by the compiler.</param>
|
||||
[MessageTemplateFormatMethod("messageTemplate")]
|
||||
public static void Verbose(Exception exception, string messageTemplate, object[] propertyValues, bool show = false, [CallerMemberName] string callerMethodeName = "", [CallerFilePath] string callerFilePath = "", [CallerLineNumber] int callerLineNumer = -1)
|
||||
{
|
||||
using (LogContext.PushProperty("CallingContext", new { callerMethodeName, callerFilePath, callerLineNumer}))
|
||||
{
|
||||
_MainLog.Verbose(exception, messageTemplate, propertyValues);
|
||||
}
|
||||
if(show)
|
||||
_ShowLogAssistent(messageTemplate, propertyValues, callerMethodeName, callerFilePath, callerLineNumer);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Debug functions
|
||||
|
||||
/// <summary>
|
||||
/// Write an event with the Debug level to the Debug log.
|
||||
/// </summary>
|
||||
/// <param name="messageTemplate">Message template for this event.</param>
|
||||
/// <param name="show">True if an message should be shown to the user, false otherwise.</param>
|
||||
/// <param name="callerMethodeName">Don't use! The methode name of the caller will be filled automatically by the compiler.</param>
|
||||
/// <param name="callerFilePath">Don't use! The filepath of the caller will be filled automatically by the compiler.</param>
|
||||
/// <param name="callerLineNumer">Don't use! The line number of the caller will be filled automatically by the compiler.</param>
|
||||
[MessageTemplateFormatMethod("messageTemplate")]
|
||||
public static void Debug(string messageTemplate, bool show = false, [CallerMemberName] string callerMethodeName = "", [CallerFilePath] string callerFilePath = "", [CallerLineNumber] int callerLineNumer = -1)
|
||||
{
|
||||
using (LogContext.PushProperty("CallingContext", new { callerMethodeName, callerFilePath, callerLineNumer}))
|
||||
{
|
||||
_MainLog.Debug(messageTemplate);
|
||||
}
|
||||
if(show)
|
||||
_ShowLogAssistent(messageTemplate, null, callerMethodeName, callerFilePath, callerLineNumer);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write an event with the Debug level with additional propertyValues to the Debug log.
|
||||
/// </summary>
|
||||
/// <param name="messageTemplate">Message template for this event.</param>
|
||||
/// <param name="propertyValues">Data inserted into the message template.</param>
|
||||
/// <param name="show">True if an message should be shown to the user, false otherwise.</param>
|
||||
/// <param name="callerMethodeName">Don't use! The methode name of the caller will be filled automatically by the compiler.</param>
|
||||
/// <param name="callerFilePath">Don't use! The filepath of the caller will be filled automatically by the compiler.</param>
|
||||
/// <param name="callerLineNumer">Don't use! The line number of the caller will be filled automatically by the compiler.</param>
|
||||
[MessageTemplateFormatMethod("messageTemplate")]
|
||||
public static void Debug(string messageTemplate, object[] propertyValues, bool show = false, [CallerMemberName] string callerMethodeName = "", [CallerFilePath] string callerFilePath = "", [CallerLineNumber] int callerLineNumer = -1)
|
||||
{
|
||||
using (LogContext.PushProperty("CallingContext", new { callerMethodeName, callerFilePath, callerLineNumer}))
|
||||
{
|
||||
_MainLog.Debug(messageTemplate, propertyValues);
|
||||
}
|
||||
if(show)
|
||||
_ShowLogAssistent(messageTemplate, propertyValues, callerMethodeName, callerFilePath, callerLineNumer);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write an event with the Debug level and associated exception to the Debug log.
|
||||
/// </summary>
|
||||
/// <param name="exception">Exception of this event.</param>
|
||||
/// <param name="messageTemplate">Message template for this event.</param>
|
||||
/// <param name="show">True if an message should be shown to the user, false otherwise.</param>
|
||||
/// <param name="callerMethodeName">Don't use! The methode name of the caller will be filled automatically by the compiler.</param>
|
||||
/// <param name="callerFilePath">Don't use! The filepath of the caller will be filled automatically by the compiler.</param>
|
||||
/// <param name="callerLineNumer">Don't use! The line number of the caller will be filled automatically by the compiler.</param>
|
||||
[MessageTemplateFormatMethod("messageTemplate")]
|
||||
public static void Debug(Exception exception, string messageTemplate, bool show = false, [CallerMemberName] string callerMethodeName = "", [CallerFilePath] string callerFilePath = "", [CallerLineNumber] int callerLineNumer = -1)
|
||||
{
|
||||
using (LogContext.PushProperty("CallingContext", new { callerMethodeName, callerFilePath, callerLineNumer}))
|
||||
{
|
||||
_MainLog.Debug( exception, messageTemplate);
|
||||
}
|
||||
if(show)
|
||||
_ShowLogAssistent(messageTemplate, null, callerMethodeName, callerFilePath, callerLineNumer);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write an event with the Debug level with additional propertyValues and associated exception to the Debug log.
|
||||
/// </summary>
|
||||
/// <param name="exception">Exception of this event.</param>
|
||||
/// <param name="messageTemplate">Message template for this event.</param>
|
||||
/// <param name="propertyValues">Data inserted into the message template.</param>
|
||||
/// <param name="show">True if an message should be shown to the user, false otherwise.</param>
|
||||
/// <param name="callerMethodeName">Don't use! The methode name of the caller will be filled automatically by the compiler.</param>
|
||||
/// <param name="callerFilePath">Don't use! The filepath of the caller will be filled automatically by the compiler.</param>
|
||||
/// <param name="callerLineNumer">Don't use! The line number of the caller will be filled automatically by the compiler.</param>
|
||||
[MessageTemplateFormatMethod("messageTemplate")]
|
||||
public static void Debug(Exception exception, string messageTemplate, object[] propertyValues, bool show = false, [CallerMemberName] string callerMethodeName = "", [CallerFilePath] string callerFilePath = "", [CallerLineNumber] int callerLineNumer = -1)
|
||||
{
|
||||
using (LogContext.PushProperty("CallingContext", new { callerMethodeName, callerFilePath, callerLineNumer}))
|
||||
{
|
||||
_MainLog.Debug(exception, messageTemplate, propertyValues);
|
||||
}
|
||||
if(show)
|
||||
_ShowLogAssistent(messageTemplate, propertyValues, callerMethodeName, callerFilePath, callerLineNumer);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Information functions
|
||||
|
||||
/// <summary>
|
||||
/// Write an event with the Information level to the Information log.
|
||||
/// </summary>
|
||||
/// <param name="messageTemplate">Message template for this event.</param>
|
||||
/// <param name="show">True if an message should be shown to the user, false otherwise.</param>
|
||||
/// <param name="callerMethodeName">Don't use! The methode name of the caller will be filled automatically by the compiler.</param>
|
||||
/// <param name="callerFilePath">Don't use! The filepath of the caller will be filled automatically by the compiler.</param>
|
||||
/// <param name="callerLineNumer">Don't use! The line number of the caller will be filled automatically by the compiler.</param>
|
||||
[MessageTemplateFormatMethod("messageTemplate")]
|
||||
public static void Information(string messageTemplate, bool show = false, [CallerMemberName] string callerMethodeName = "", [CallerFilePath] string callerFilePath = "", [CallerLineNumber] int callerLineNumer = -1)
|
||||
{
|
||||
using (LogContext.PushProperty("CallingContext", new { callerMethodeName, callerFilePath, callerLineNumer}))
|
||||
{
|
||||
_MainLog.Information(messageTemplate);
|
||||
}
|
||||
if(show)
|
||||
_ShowLogAssistent(messageTemplate, null, callerMethodeName, callerFilePath, callerLineNumer);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write an event with the Information level with additional propertyValues to the Information log.
|
||||
/// </summary>
|
||||
/// <param name="messageTemplate">Message template for this event.</param>
|
||||
/// <param name="propertyValues">Data inserted into the message template.</param>
|
||||
/// <param name="show">True if an message should be shown to the user, false otherwise.</param>
|
||||
/// <param name="callerMethodeName">Don't use! The methode name of the caller will be filled automatically by the compiler.</param>
|
||||
/// <param name="callerFilePath">Don't use! The filepath of the caller will be filled automatically by the compiler.</param>
|
||||
/// <param name="callerLineNumer">Don't use! The line number of the caller will be filled automatically by the compiler.</param>
|
||||
[MessageTemplateFormatMethod("messageTemplate")]
|
||||
public static void Information(string messageTemplate, object[] propertyValues, bool show = false, [CallerMemberName] string callerMethodeName = "", [CallerFilePath] string callerFilePath = "", [CallerLineNumber] int callerLineNumer = -1)
|
||||
{
|
||||
using (LogContext.PushProperty("CallingContext", new { callerMethodeName, callerFilePath, callerLineNumer}))
|
||||
{
|
||||
_MainLog.Information(messageTemplate, propertyValues);
|
||||
}
|
||||
if(show)
|
||||
_ShowLogAssistent(messageTemplate, propertyValues, callerMethodeName, callerFilePath, callerLineNumer);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write an event with the Information level and associated exception to the Information log.
|
||||
/// </summary>
|
||||
/// <param name="exception">Exception of this event.</param>
|
||||
/// <param name="messageTemplate">Message template for this event.</param>
|
||||
/// <param name="show">True if an message should be shown to the user, false otherwise.</param>
|
||||
/// <param name="callerMethodeName">Don't use! The methode name of the caller will be filled automatically by the compiler.</param>
|
||||
/// <param name="callerFilePath">Don't use! The filepath of the caller will be filled automatically by the compiler.</param>
|
||||
/// <param name="callerLineNumer">Don't use! The line number of the caller will be filled automatically by the compiler.</param>
|
||||
[MessageTemplateFormatMethod("messageTemplate")]
|
||||
public static void Information(Exception exception, string messageTemplate, bool show = false, [CallerMemberName] string callerMethodeName = "", [CallerFilePath] string callerFilePath = "", [CallerLineNumber] int callerLineNumer = -1)
|
||||
{
|
||||
using (LogContext.PushProperty("CallingContext", new { callerMethodeName, callerFilePath, callerLineNumer}))
|
||||
{
|
||||
_MainLog.Information( exception, messageTemplate);
|
||||
}
|
||||
if(show)
|
||||
_ShowLogAssistent(messageTemplate, null, callerMethodeName, callerFilePath, callerLineNumer);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write an event with the Information level with additional propertyValues and associated exception to the Information log.
|
||||
/// </summary>
|
||||
/// <param name="exception">Exception of this event.</param>
|
||||
/// <param name="messageTemplate">Message template for this event.</param>
|
||||
/// <param name="propertyValues">Data inserted into the message template.</param>
|
||||
/// <param name="show">True if an message should be shown to the user, false otherwise.</param>
|
||||
/// <param name="callerMethodeName">Don't use! The methode name of the caller will be filled automatically by the compiler.</param>
|
||||
/// <param name="callerFilePath">Don't use! The filepath of the caller will be filled automatically by the compiler.</param>
|
||||
/// <param name="callerLineNumer">Don't use! The line number of the caller will be filled automatically by the compiler.</param>
|
||||
[MessageTemplateFormatMethod("messageTemplate")]
|
||||
public static void Information(Exception exception, string messageTemplate, object[] propertyValues, bool show = false, [CallerMemberName] string callerMethodeName = "", [CallerFilePath] string callerFilePath = "", [CallerLineNumber] int callerLineNumer = -1)
|
||||
{
|
||||
using (LogContext.PushProperty("CallingContext", new { callerMethodeName, callerFilePath, callerLineNumer}))
|
||||
{
|
||||
_MainLog.Information(exception, messageTemplate, propertyValues);
|
||||
}
|
||||
if(show)
|
||||
_ShowLogAssistent(messageTemplate, propertyValues, callerMethodeName, callerFilePath, callerLineNumer);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Warning functions
|
||||
|
||||
/// <summary>
|
||||
/// Write an event with the Warning level to the Warning log.
|
||||
/// </summary>
|
||||
/// <param name="messageTemplate">Message template for this event.</param>
|
||||
/// <param name="show">True if an message should be shown to the user, false otherwise.</param>
|
||||
/// <param name="callerMethodeName">Don't use! The methode name of the caller will be filled automatically by the compiler.</param>
|
||||
/// <param name="callerFilePath">Don't use! The filepath of the caller will be filled automatically by the compiler.</param>
|
||||
/// <param name="callerLineNumer">Don't use! The line number of the caller will be filled automatically by the compiler.</param>
|
||||
[MessageTemplateFormatMethod("messageTemplate")]
|
||||
public static void Warning(string messageTemplate, bool show = false, [CallerMemberName] string callerMethodeName = "", [CallerFilePath] string callerFilePath = "", [CallerLineNumber] int callerLineNumer = -1)
|
||||
{
|
||||
using (LogContext.PushProperty("CallingContext", new { callerMethodeName, callerFilePath, callerLineNumer}))
|
||||
{
|
||||
_MainLog.Warning(messageTemplate);
|
||||
}
|
||||
if(show)
|
||||
_ShowLogAssistent(messageTemplate, null, callerMethodeName, callerFilePath, callerLineNumer);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write an event with the Warning level with additional propertyValues to the Warning log.
|
||||
/// </summary>
|
||||
/// <param name="messageTemplate">Message template for this event.</param>
|
||||
/// <param name="propertyValues">Data inserted into the message template.</param>
|
||||
/// <param name="show">True if an message should be shown to the user, false otherwise.</param>
|
||||
/// <param name="callerMethodeName">Don't use! The methode name of the caller will be filled automatically by the compiler.</param>
|
||||
/// <param name="callerFilePath">Don't use! The filepath of the caller will be filled automatically by the compiler.</param>
|
||||
/// <param name="callerLineNumer">Don't use! The line number of the caller will be filled automatically by the compiler.</param>
|
||||
[MessageTemplateFormatMethod("messageTemplate")]
|
||||
public static void Warning(string messageTemplate, object[] propertyValues, bool show = false, [CallerMemberName] string callerMethodeName = "", [CallerFilePath] string callerFilePath = "", [CallerLineNumber] int callerLineNumer = -1)
|
||||
{
|
||||
using (LogContext.PushProperty("CallingContext", new { callerMethodeName, callerFilePath, callerLineNumer}))
|
||||
{
|
||||
_MainLog.Warning(messageTemplate, propertyValues);
|
||||
}
|
||||
if(show)
|
||||
_ShowLogAssistent(messageTemplate, propertyValues, callerMethodeName, callerFilePath, callerLineNumer);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write an event with the Warning level and associated exception to the Warning log.
|
||||
/// </summary>
|
||||
/// <param name="exception">Exception of this event.</param>
|
||||
/// <param name="messageTemplate">Message template for this event.</param>
|
||||
/// <param name="show">True if an message should be shown to the user, false otherwise.</param>
|
||||
/// <param name="callerMethodeName">Don't use! The methode name of the caller will be filled automatically by the compiler.</param>
|
||||
/// <param name="callerFilePath">Don't use! The filepath of the caller will be filled automatically by the compiler.</param>
|
||||
/// <param name="callerLineNumer">Don't use! The line number of the caller will be filled automatically by the compiler.</param>
|
||||
[MessageTemplateFormatMethod("messageTemplate")]
|
||||
public static void Warning(Exception exception, string messageTemplate, bool show = false, [CallerMemberName] string callerMethodeName = "", [CallerFilePath] string callerFilePath = "", [CallerLineNumber] int callerLineNumer = -1)
|
||||
{
|
||||
using (LogContext.PushProperty("CallingContext", new { callerMethodeName, callerFilePath, callerLineNumer}))
|
||||
{
|
||||
_MainLog.Warning( exception, messageTemplate);
|
||||
}
|
||||
if(show)
|
||||
_ShowLogAssistent(messageTemplate, null, callerMethodeName, callerFilePath, callerLineNumer);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write an event with the Warning level with additional propertyValues and associated exception to the Warning log.
|
||||
/// </summary>
|
||||
/// <param name="exception">Exception of this event.</param>
|
||||
/// <param name="messageTemplate">Message template for this event.</param>
|
||||
/// <param name="propertyValues">Data inserted into the message template.</param>
|
||||
/// <param name="show">True if an message should be shown to the user, false otherwise.</param>
|
||||
/// <param name="callerMethodeName">Don't use! The methode name of the caller will be filled automatically by the compiler.</param>
|
||||
/// <param name="callerFilePath">Don't use! The filepath of the caller will be filled automatically by the compiler.</param>
|
||||
/// <param name="callerLineNumer">Don't use! The line number of the caller will be filled automatically by the compiler.</param>
|
||||
[MessageTemplateFormatMethod("messageTemplate")]
|
||||
public static void Warning(Exception exception, string messageTemplate, object[] propertyValues, bool show = false, [CallerMemberName] string callerMethodeName = "", [CallerFilePath] string callerFilePath = "", [CallerLineNumber] int callerLineNumer = -1)
|
||||
{
|
||||
using (LogContext.PushProperty("CallingContext", new { callerMethodeName, callerFilePath, callerLineNumer}))
|
||||
{
|
||||
_MainLog.Warning(exception, messageTemplate, propertyValues);
|
||||
}
|
||||
if(show)
|
||||
_ShowLogAssistent(messageTemplate, propertyValues, callerMethodeName, callerFilePath, callerLineNumer);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Error functions
|
||||
|
||||
/// <summary>
|
||||
/// Write an event with the Error level to the Error log.
|
||||
/// </summary>
|
||||
/// <param name="messageTemplate">Message template for this event.</param>
|
||||
/// <param name="show">True if an message should be shown to the user, false otherwise.</param>
|
||||
/// <param name="callerMethodeName">Don't use! The methode name of the caller will be filled automatically by the compiler.</param>
|
||||
/// <param name="callerFilePath">Don't use! The filepath of the caller will be filled automatically by the compiler.</param>
|
||||
/// <param name="callerLineNumer">Don't use! The line number of the caller will be filled automatically by the compiler.</param>
|
||||
[MessageTemplateFormatMethod("messageTemplate")]
|
||||
public static void Error(string messageTemplate, bool show = false, [CallerMemberName] string callerMethodeName = "", [CallerFilePath] string callerFilePath = "", [CallerLineNumber] int callerLineNumer = -1)
|
||||
{
|
||||
using (LogContext.PushProperty("CallingContext", new { callerMethodeName, callerFilePath, callerLineNumer}))
|
||||
{
|
||||
_MainLog.Error(messageTemplate);
|
||||
}
|
||||
if(show)
|
||||
_ShowLogAssistent(messageTemplate, null, callerMethodeName, callerFilePath, callerLineNumer);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write an event with the Error level with additional propertyValues to the Error log.
|
||||
/// </summary>
|
||||
/// <param name="messageTemplate">Message template for this event.</param>
|
||||
/// <param name="propertyValues">Data inserted into the message template.</param>
|
||||
/// <param name="show">True if an message should be shown to the user, false otherwise.</param>
|
||||
/// <param name="callerMethodeName">Don't use! The methode name of the caller will be filled automatically by the compiler.</param>
|
||||
/// <param name="callerFilePath">Don't use! The filepath of the caller will be filled automatically by the compiler.</param>
|
||||
/// <param name="callerLineNumer">Don't use! The line number of the caller will be filled automatically by the compiler.</param>
|
||||
[MessageTemplateFormatMethod("messageTemplate")]
|
||||
public static void Error(string messageTemplate, object[] propertyValues, bool show = false, [CallerMemberName] string callerMethodeName = "", [CallerFilePath] string callerFilePath = "", [CallerLineNumber] int callerLineNumer = -1)
|
||||
{
|
||||
using (LogContext.PushProperty("CallingContext", new { callerMethodeName, callerFilePath, callerLineNumer}))
|
||||
{
|
||||
_MainLog.Error(messageTemplate, propertyValues);
|
||||
}
|
||||
if(show)
|
||||
_ShowLogAssistent(messageTemplate, propertyValues, callerMethodeName, callerFilePath, callerLineNumer);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write an event with the Error level and associated exception to the Error log.
|
||||
/// </summary>
|
||||
/// <param name="exception">Exception of this event.</param>
|
||||
/// <param name="messageTemplate">Message template for this event.</param>
|
||||
/// <param name="show">True if an message should be shown to the user, false otherwise.</param>
|
||||
/// <param name="callerMethodeName">Don't use! The methode name of the caller will be filled automatically by the compiler.</param>
|
||||
/// <param name="callerFilePath">Don't use! The filepath of the caller will be filled automatically by the compiler.</param>
|
||||
/// <param name="callerLineNumer">Don't use! The line number of the caller will be filled automatically by the compiler.</param>
|
||||
[MessageTemplateFormatMethod("messageTemplate")]
|
||||
public static void Error(Exception exception, string messageTemplate, bool show = false, [CallerMemberName] string callerMethodeName = "", [CallerFilePath] string callerFilePath = "", [CallerLineNumber] int callerLineNumer = -1)
|
||||
{
|
||||
using (LogContext.PushProperty("CallingContext", new { callerMethodeName, callerFilePath, callerLineNumer}))
|
||||
{
|
||||
_MainLog.Error( exception, messageTemplate);
|
||||
}
|
||||
if(show)
|
||||
_ShowLogAssistent(messageTemplate, null, callerMethodeName, callerFilePath, callerLineNumer);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write an event with the Error level with additional propertyValues and associated exception to the Error log.
|
||||
/// </summary>
|
||||
/// <param name="exception">Exception of this event.</param>
|
||||
/// <param name="messageTemplate">Message template for this event.</param>
|
||||
/// <param name="propertyValues">Data inserted into the message template.</param>
|
||||
/// <param name="show">True if an message should be shown to the user, false otherwise.</param>
|
||||
/// <param name="callerMethodeName">Don't use! The methode name of the caller will be filled automatically by the compiler.</param>
|
||||
/// <param name="callerFilePath">Don't use! The filepath of the caller will be filled automatically by the compiler.</param>
|
||||
/// <param name="callerLineNumer">Don't use! The line number of the caller will be filled automatically by the compiler.</param>
|
||||
[MessageTemplateFormatMethod("messageTemplate")]
|
||||
public static void Error(Exception exception, string messageTemplate, object[] propertyValues, bool show = false, [CallerMemberName] string callerMethodeName = "", [CallerFilePath] string callerFilePath = "", [CallerLineNumber] int callerLineNumer = -1)
|
||||
{
|
||||
using (LogContext.PushProperty("CallingContext", new { callerMethodeName, callerFilePath, callerLineNumer}))
|
||||
{
|
||||
_MainLog.Error(exception, messageTemplate, propertyValues);
|
||||
}
|
||||
if(show)
|
||||
_ShowLogAssistent(messageTemplate, propertyValues, callerMethodeName, callerFilePath, callerLineNumer);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Fatal functions
|
||||
|
||||
/// <summary>
|
||||
/// Write an event with the Fatal level to the Fatal log.
|
||||
/// </summary>
|
||||
/// <param name="messageTemplate">Message template for this event.</param>
|
||||
/// <param name="show">True if an message should be shown to the user, false otherwise.</param>
|
||||
/// <param name="callerMethodeName">Don't use! The methode name of the caller will be filled automatically by the compiler.</param>
|
||||
/// <param name="callerFilePath">Don't use! The filepath of the caller will be filled automatically by the compiler.</param>
|
||||
/// <param name="callerLineNumer">Don't use! The line number of the caller will be filled automatically by the compiler.</param>
|
||||
[MessageTemplateFormatMethod("messageTemplate")]
|
||||
public static void Fatal(string messageTemplate, bool show = true, [CallerMemberName] string callerMethodeName = "", [CallerFilePath] string callerFilePath = "", [CallerLineNumber] int callerLineNumer = -1)
|
||||
{
|
||||
using (LogContext.PushProperty("CallingContext", new { callerMethodeName, callerFilePath, callerLineNumer}))
|
||||
{
|
||||
_MainLog.Fatal(messageTemplate);
|
||||
}
|
||||
if(show)
|
||||
_ShowLogAssistent(messageTemplate, null, callerMethodeName, callerFilePath, callerLineNumer);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write an event with the Fatal level with additional propertyValues to the Fatal log.
|
||||
/// </summary>
|
||||
/// <param name="messageTemplate">Message template for this event.</param>
|
||||
/// <param name="propertyValues">Data inserted into the message template.</param>
|
||||
/// <param name="show">True if an message should be shown to the user, false otherwise.</param>
|
||||
/// <param name="callerMethodeName">Don't use! The methode name of the caller will be filled automatically by the compiler.</param>
|
||||
/// <param name="callerFilePath">Don't use! The filepath of the caller will be filled automatically by the compiler.</param>
|
||||
/// <param name="callerLineNumer">Don't use! The line number of the caller will be filled automatically by the compiler.</param>
|
||||
[MessageTemplateFormatMethod("messageTemplate")]
|
||||
public static void Fatal(string messageTemplate, object[] propertyValues, bool show = true, [CallerMemberName] string callerMethodeName = "", [CallerFilePath] string callerFilePath = "", [CallerLineNumber] int callerLineNumer = -1)
|
||||
{
|
||||
using (LogContext.PushProperty("CallingContext", new { callerMethodeName, callerFilePath, callerLineNumer}))
|
||||
{
|
||||
_MainLog.Fatal(messageTemplate, propertyValues);
|
||||
}
|
||||
if(show)
|
||||
_ShowLogAssistent(messageTemplate, propertyValues, callerMethodeName, callerFilePath, callerLineNumer);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write an event with the Fatal level and associated exception to the Fatal log.
|
||||
/// </summary>
|
||||
/// <param name="exception">Exception of this event.</param>
|
||||
/// <param name="messageTemplate">Message template for this event.</param>
|
||||
/// <param name="show">True if an message should be shown to the user, false otherwise.</param>
|
||||
/// <param name="callerMethodeName">Don't use! The methode name of the caller will be filled automatically by the compiler.</param>
|
||||
/// <param name="callerFilePath">Don't use! The filepath of the caller will be filled automatically by the compiler.</param>
|
||||
/// <param name="callerLineNumer">Don't use! The line number of the caller will be filled automatically by the compiler.</param>
|
||||
[MessageTemplateFormatMethod("messageTemplate")]
|
||||
public static void Fatal(Exception exception, string messageTemplate, bool show = true, [CallerMemberName] string callerMethodeName = "", [CallerFilePath] string callerFilePath = "", [CallerLineNumber] int callerLineNumer = -1)
|
||||
{
|
||||
using (LogContext.PushProperty("CallingContext", new { callerMethodeName, callerFilePath, callerLineNumer}))
|
||||
{
|
||||
_MainLog.Fatal( exception, messageTemplate);
|
||||
}
|
||||
if(show)
|
||||
_ShowLogAssistent(messageTemplate, null, callerMethodeName, callerFilePath, callerLineNumer);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write an event with the Fatal level with additional propertyValues and associated exception to the Fatal log.
|
||||
/// </summary>
|
||||
/// <param name="exception">Exception of this event.</param>
|
||||
/// <param name="messageTemplate">Message template for this event.</param>
|
||||
/// <param name="propertyValues">Data inserted into the message template.</param>
|
||||
/// <param name="show">True if an message should be shown to the user, false otherwise.</param>
|
||||
/// <param name="callerMethodeName">Don't use! The methode name of the caller will be filled automatically by the compiler.</param>
|
||||
/// <param name="callerFilePath">Don't use! The filepath of the caller will be filled automatically by the compiler.</param>
|
||||
/// <param name="callerLineNumer">Don't use! The line number of the caller will be filled automatically by the compiler.</param>
|
||||
[MessageTemplateFormatMethod("messageTemplate")]
|
||||
public static void Fatal(Exception exception, string messageTemplate, object[] propertyValues, bool show = true, [CallerMemberName] string callerMethodeName = "", [CallerFilePath] string callerFilePath = "", [CallerLineNumber] int callerLineNumer = -1)
|
||||
{
|
||||
using (LogContext.PushProperty("CallingContext", new { callerMethodeName, callerFilePath, callerLineNumer}))
|
||||
{
|
||||
_MainLog.Fatal(exception, messageTemplate, propertyValues);
|
||||
}
|
||||
if(show)
|
||||
_ShowLogAssistent(messageTemplate, propertyValues, callerMethodeName, callerFilePath, callerLineNumer);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
[SuppressMessage("ReSharper", "MemberHidesStaticFromOuterClass")]
|
||||
public static class CSongLog
|
||||
{
|
||||
|
||||
#region Verbose functions
|
||||
|
||||
/// <summary>
|
||||
/// Write an event with the Verbose level to the Verbose log.
|
||||
/// </summary>
|
||||
/// <param name="messageTemplate">Message template for this event.</param>
|
||||
/// <param name="callerMethodeName">Don't use! The methode name of the caller will be filled automatically by the compiler.</param>
|
||||
/// <param name="callerFilePath">Don't use! The filepath of the caller will be filled automatically by the compiler.</param>
|
||||
/// <param name="callerLineNumer">Don't use! The line number of the caller will be filled automatically by the compiler.</param>
|
||||
[MessageTemplateFormatMethod("messageTemplate")]
|
||||
public static void Verbose(string messageTemplate, [CallerMemberName] string callerMethodeName = "", [CallerFilePath] string callerFilePath = "", [CallerLineNumber] int callerLineNumer = -1)
|
||||
{
|
||||
using (LogContext.PushProperty("CallingContext", new { callerMethodeName, callerFilePath, callerLineNumer}))
|
||||
{
|
||||
_SongLog.Verbose(messageTemplate);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write an event with the Verbose level with additional propertyValues to the Verbose log.
|
||||
/// </summary>
|
||||
/// <param name="messageTemplate">Message template for this event.</param>
|
||||
/// <param name="propertyValues">Data inserted into the message template.</param>
|
||||
/// <param name="callerMethodeName">Don't use! The methode name of the caller will be filled automatically by the compiler.</param>
|
||||
/// <param name="callerFilePath">Don't use! The filepath of the caller will be filled automatically by the compiler.</param>
|
||||
/// <param name="callerLineNumer">Don't use! The line number of the caller will be filled automatically by the compiler.</param>
|
||||
[MessageTemplateFormatMethod("messageTemplate")]
|
||||
public static void Verbose(string messageTemplate, object[] propertyValues, [CallerMemberName] string callerMethodeName = "", [CallerFilePath] string callerFilePath = "", [CallerLineNumber] int callerLineNumer = -1)
|
||||
{
|
||||
using (LogContext.PushProperty("CallingContext", new { callerMethodeName, callerFilePath, callerLineNumer}))
|
||||
{
|
||||
_SongLog.Verbose(messageTemplate, propertyValues);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write an event with the Verbose level and associated exception to the Verbose log.
|
||||
/// </summary>
|
||||
/// <param name="exception">Exception of this event.</param>
|
||||
/// <param name="messageTemplate">Message template for this event.</param>
|
||||
/// <param name="callerMethodeName">Don't use! The methode name of the caller will be filled automatically by the compiler.</param>
|
||||
/// <param name="callerFilePath">Don't use! The filepath of the caller will be filled automatically by the compiler.</param>
|
||||
/// <param name="callerLineNumer">Don't use! The line number of the caller will be filled automatically by the compiler.</param>
|
||||
[MessageTemplateFormatMethod("messageTemplate")]
|
||||
public static void Verbose(Exception exception, string messageTemplate, [CallerMemberName] string callerMethodeName = "", [CallerFilePath] string callerFilePath = "", [CallerLineNumber] int callerLineNumer = -1)
|
||||
{
|
||||
using (LogContext.PushProperty("CallingContext", new { callerMethodeName, callerFilePath, callerLineNumer}))
|
||||
{
|
||||
_SongLog.Verbose( exception, messageTemplate);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write an event with the Verbose level with additional propertyValues and associated exception to the Verbose log.
|
||||
/// </summary>
|
||||
/// <param name="exception">Exception of this event.</param>
|
||||
/// <param name="messageTemplate">Message template for this event.</param>
|
||||
/// <param name="propertyValues">Data inserted into the message template.</param>
|
||||
/// <param name="callerMethodeName">Don't use! The methode name of the caller will be filled automatically by the compiler.</param>
|
||||
/// <param name="callerFilePath">Don't use! The filepath of the caller will be filled automatically by the compiler.</param>
|
||||
/// <param name="callerLineNumer">Don't use! The line number of the caller will be filled automatically by the compiler.</param>
|
||||
[MessageTemplateFormatMethod("messageTemplate")]
|
||||
public static void Verbose(Exception exception, string messageTemplate, object[] propertyValues, [CallerMemberName] string callerMethodeName = "", [CallerFilePath] string callerFilePath = "", [CallerLineNumber] int callerLineNumer = -1)
|
||||
{
|
||||
using (LogContext.PushProperty("CallingContext", new { callerMethodeName, callerFilePath, callerLineNumer}))
|
||||
{
|
||||
_SongLog.Verbose(exception, messageTemplate, propertyValues);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Debug functions
|
||||
|
||||
/// <summary>
|
||||
/// Write an event with the Debug level to the Debug log.
|
||||
/// </summary>
|
||||
/// <param name="messageTemplate">Message template for this event.</param>
|
||||
/// <param name="callerMethodeName">Don't use! The methode name of the caller will be filled automatically by the compiler.</param>
|
||||
/// <param name="callerFilePath">Don't use! The filepath of the caller will be filled automatically by the compiler.</param>
|
||||
/// <param name="callerLineNumer">Don't use! The line number of the caller will be filled automatically by the compiler.</param>
|
||||
[MessageTemplateFormatMethod("messageTemplate")]
|
||||
public static void Debug(string messageTemplate, [CallerMemberName] string callerMethodeName = "", [CallerFilePath] string callerFilePath = "", [CallerLineNumber] int callerLineNumer = -1)
|
||||
{
|
||||
using (LogContext.PushProperty("CallingContext", new { callerMethodeName, callerFilePath, callerLineNumer}))
|
||||
{
|
||||
_SongLog.Debug(messageTemplate);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write an event with the Debug level with additional propertyValues to the Debug log.
|
||||
/// </summary>
|
||||
/// <param name="messageTemplate">Message template for this event.</param>
|
||||
/// <param name="propertyValues">Data inserted into the message template.</param>
|
||||
/// <param name="callerMethodeName">Don't use! The methode name of the caller will be filled automatically by the compiler.</param>
|
||||
/// <param name="callerFilePath">Don't use! The filepath of the caller will be filled automatically by the compiler.</param>
|
||||
/// <param name="callerLineNumer">Don't use! The line number of the caller will be filled automatically by the compiler.</param>
|
||||
[MessageTemplateFormatMethod("messageTemplate")]
|
||||
public static void Debug(string messageTemplate, object[] propertyValues, [CallerMemberName] string callerMethodeName = "", [CallerFilePath] string callerFilePath = "", [CallerLineNumber] int callerLineNumer = -1)
|
||||
{
|
||||
using (LogContext.PushProperty("CallingContext", new { callerMethodeName, callerFilePath, callerLineNumer}))
|
||||
{
|
||||
_SongLog.Debug(messageTemplate, propertyValues);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write an event with the Debug level and associated exception to the Debug log.
|
||||
/// </summary>
|
||||
/// <param name="exception">Exception of this event.</param>
|
||||
/// <param name="messageTemplate">Message template for this event.</param>
|
||||
/// <param name="callerMethodeName">Don't use! The methode name of the caller will be filled automatically by the compiler.</param>
|
||||
/// <param name="callerFilePath">Don't use! The filepath of the caller will be filled automatically by the compiler.</param>
|
||||
/// <param name="callerLineNumer">Don't use! The line number of the caller will be filled automatically by the compiler.</param>
|
||||
[MessageTemplateFormatMethod("messageTemplate")]
|
||||
public static void Debug(Exception exception, string messageTemplate, [CallerMemberName] string callerMethodeName = "", [CallerFilePath] string callerFilePath = "", [CallerLineNumber] int callerLineNumer = -1)
|
||||
{
|
||||
using (LogContext.PushProperty("CallingContext", new { callerMethodeName, callerFilePath, callerLineNumer}))
|
||||
{
|
||||
_SongLog.Debug( exception, messageTemplate);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write an event with the Debug level with additional propertyValues and associated exception to the Debug log.
|
||||
/// </summary>
|
||||
/// <param name="exception">Exception of this event.</param>
|
||||
/// <param name="messageTemplate">Message template for this event.</param>
|
||||
/// <param name="propertyValues">Data inserted into the message template.</param>
|
||||
/// <param name="callerMethodeName">Don't use! The methode name of the caller will be filled automatically by the compiler.</param>
|
||||
/// <param name="callerFilePath">Don't use! The filepath of the caller will be filled automatically by the compiler.</param>
|
||||
/// <param name="callerLineNumer">Don't use! The line number of the caller will be filled automatically by the compiler.</param>
|
||||
[MessageTemplateFormatMethod("messageTemplate")]
|
||||
public static void Debug(Exception exception, string messageTemplate, object[] propertyValues, [CallerMemberName] string callerMethodeName = "", [CallerFilePath] string callerFilePath = "", [CallerLineNumber] int callerLineNumer = -1)
|
||||
{
|
||||
using (LogContext.PushProperty("CallingContext", new { callerMethodeName, callerFilePath, callerLineNumer}))
|
||||
{
|
||||
_SongLog.Debug(exception, messageTemplate, propertyValues);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Information functions
|
||||
|
||||
/// <summary>
|
||||
/// Write an event with the Information level to the Information log.
|
||||
/// </summary>
|
||||
/// <param name="messageTemplate">Message template for this event.</param>
|
||||
/// <param name="callerMethodeName">Don't use! The methode name of the caller will be filled automatically by the compiler.</param>
|
||||
/// <param name="callerFilePath">Don't use! The filepath of the caller will be filled automatically by the compiler.</param>
|
||||
/// <param name="callerLineNumer">Don't use! The line number of the caller will be filled automatically by the compiler.</param>
|
||||
[MessageTemplateFormatMethod("messageTemplate")]
|
||||
public static void Information(string messageTemplate, [CallerMemberName] string callerMethodeName = "", [CallerFilePath] string callerFilePath = "", [CallerLineNumber] int callerLineNumer = -1)
|
||||
{
|
||||
using (LogContext.PushProperty("CallingContext", new { callerMethodeName, callerFilePath, callerLineNumer}))
|
||||
{
|
||||
_SongLog.Information(messageTemplate);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write an event with the Information level with additional propertyValues to the Information log.
|
||||
/// </summary>
|
||||
/// <param name="messageTemplate">Message template for this event.</param>
|
||||
/// <param name="propertyValues">Data inserted into the message template.</param>
|
||||
/// <param name="callerMethodeName">Don't use! The methode name of the caller will be filled automatically by the compiler.</param>
|
||||
/// <param name="callerFilePath">Don't use! The filepath of the caller will be filled automatically by the compiler.</param>
|
||||
/// <param name="callerLineNumer">Don't use! The line number of the caller will be filled automatically by the compiler.</param>
|
||||
[MessageTemplateFormatMethod("messageTemplate")]
|
||||
public static void Information(string messageTemplate, object[] propertyValues, [CallerMemberName] string callerMethodeName = "", [CallerFilePath] string callerFilePath = "", [CallerLineNumber] int callerLineNumer = -1)
|
||||
{
|
||||
using (LogContext.PushProperty("CallingContext", new { callerMethodeName, callerFilePath, callerLineNumer}))
|
||||
{
|
||||
_SongLog.Information(messageTemplate, propertyValues);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write an event with the Information level and associated exception to the Information log.
|
||||
/// </summary>
|
||||
/// <param name="exception">Exception of this event.</param>
|
||||
/// <param name="messageTemplate">Message template for this event.</param>
|
||||
/// <param name="callerMethodeName">Don't use! The methode name of the caller will be filled automatically by the compiler.</param>
|
||||
/// <param name="callerFilePath">Don't use! The filepath of the caller will be filled automatically by the compiler.</param>
|
||||
/// <param name="callerLineNumer">Don't use! The line number of the caller will be filled automatically by the compiler.</param>
|
||||
[MessageTemplateFormatMethod("messageTemplate")]
|
||||
public static void Information(Exception exception, string messageTemplate, [CallerMemberName] string callerMethodeName = "", [CallerFilePath] string callerFilePath = "", [CallerLineNumber] int callerLineNumer = -1)
|
||||
{
|
||||
using (LogContext.PushProperty("CallingContext", new { callerMethodeName, callerFilePath, callerLineNumer}))
|
||||
{
|
||||
_SongLog.Information( exception, messageTemplate);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write an event with the Information level with additional propertyValues and associated exception to the Information log.
|
||||
/// </summary>
|
||||
/// <param name="exception">Exception of this event.</param>
|
||||
/// <param name="messageTemplate">Message template for this event.</param>
|
||||
/// <param name="propertyValues">Data inserted into the message template.</param>
|
||||
/// <param name="callerMethodeName">Don't use! The methode name of the caller will be filled automatically by the compiler.</param>
|
||||
/// <param name="callerFilePath">Don't use! The filepath of the caller will be filled automatically by the compiler.</param>
|
||||
/// <param name="callerLineNumer">Don't use! The line number of the caller will be filled automatically by the compiler.</param>
|
||||
[MessageTemplateFormatMethod("messageTemplate")]
|
||||
public static void Information(Exception exception, string messageTemplate, object[] propertyValues, [CallerMemberName] string callerMethodeName = "", [CallerFilePath] string callerFilePath = "", [CallerLineNumber] int callerLineNumer = -1)
|
||||
{
|
||||
using (LogContext.PushProperty("CallingContext", new { callerMethodeName, callerFilePath, callerLineNumer}))
|
||||
{
|
||||
_SongLog.Information(exception, messageTemplate, propertyValues);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Warning functions
|
||||
|
||||
/// <summary>
|
||||
/// Write an event with the Warning level to the Warning log.
|
||||
/// </summary>
|
||||
/// <param name="messageTemplate">Message template for this event.</param>
|
||||
/// <param name="callerMethodeName">Don't use! The methode name of the caller will be filled automatically by the compiler.</param>
|
||||
/// <param name="callerFilePath">Don't use! The filepath of the caller will be filled automatically by the compiler.</param>
|
||||
/// <param name="callerLineNumer">Don't use! The line number of the caller will be filled automatically by the compiler.</param>
|
||||
[MessageTemplateFormatMethod("messageTemplate")]
|
||||
public static void Warning(string messageTemplate, [CallerMemberName] string callerMethodeName = "", [CallerFilePath] string callerFilePath = "", [CallerLineNumber] int callerLineNumer = -1)
|
||||
{
|
||||
using (LogContext.PushProperty("CallingContext", new { callerMethodeName, callerFilePath, callerLineNumer}))
|
||||
{
|
||||
_SongLog.Warning(messageTemplate);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write an event with the Warning level with additional propertyValues to the Warning log.
|
||||
/// </summary>
|
||||
/// <param name="messageTemplate">Message template for this event.</param>
|
||||
/// <param name="propertyValues">Data inserted into the message template.</param>
|
||||
/// <param name="callerMethodeName">Don't use! The methode name of the caller will be filled automatically by the compiler.</param>
|
||||
/// <param name="callerFilePath">Don't use! The filepath of the caller will be filled automatically by the compiler.</param>
|
||||
/// <param name="callerLineNumer">Don't use! The line number of the caller will be filled automatically by the compiler.</param>
|
||||
[MessageTemplateFormatMethod("messageTemplate")]
|
||||
public static void Warning(string messageTemplate, object[] propertyValues, [CallerMemberName] string callerMethodeName = "", [CallerFilePath] string callerFilePath = "", [CallerLineNumber] int callerLineNumer = -1)
|
||||
{
|
||||
using (LogContext.PushProperty("CallingContext", new { callerMethodeName, callerFilePath, callerLineNumer}))
|
||||
{
|
||||
_SongLog.Warning(messageTemplate, propertyValues);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write an event with the Warning level and associated exception to the Warning log.
|
||||
/// </summary>
|
||||
/// <param name="exception">Exception of this event.</param>
|
||||
/// <param name="messageTemplate">Message template for this event.</param>
|
||||
/// <param name="callerMethodeName">Don't use! The methode name of the caller will be filled automatically by the compiler.</param>
|
||||
/// <param name="callerFilePath">Don't use! The filepath of the caller will be filled automatically by the compiler.</param>
|
||||
/// <param name="callerLineNumer">Don't use! The line number of the caller will be filled automatically by the compiler.</param>
|
||||
[MessageTemplateFormatMethod("messageTemplate")]
|
||||
public static void Warning(Exception exception, string messageTemplate, [CallerMemberName] string callerMethodeName = "", [CallerFilePath] string callerFilePath = "", [CallerLineNumber] int callerLineNumer = -1)
|
||||
{
|
||||
using (LogContext.PushProperty("CallingContext", new { callerMethodeName, callerFilePath, callerLineNumer}))
|
||||
{
|
||||
_SongLog.Warning( exception, messageTemplate);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write an event with the Warning level with additional propertyValues and associated exception to the Warning log.
|
||||
/// </summary>
|
||||
/// <param name="exception">Exception of this event.</param>
|
||||
/// <param name="messageTemplate">Message template for this event.</param>
|
||||
/// <param name="propertyValues">Data inserted into the message template.</param>
|
||||
/// <param name="callerMethodeName">Don't use! The methode name of the caller will be filled automatically by the compiler.</param>
|
||||
/// <param name="callerFilePath">Don't use! The filepath of the caller will be filled automatically by the compiler.</param>
|
||||
/// <param name="callerLineNumer">Don't use! The line number of the caller will be filled automatically by the compiler.</param>
|
||||
[MessageTemplateFormatMethod("messageTemplate")]
|
||||
public static void Warning(Exception exception, string messageTemplate, object[] propertyValues, [CallerMemberName] string callerMethodeName = "", [CallerFilePath] string callerFilePath = "", [CallerLineNumber] int callerLineNumer = -1)
|
||||
{
|
||||
using (LogContext.PushProperty("CallingContext", new { callerMethodeName, callerFilePath, callerLineNumer}))
|
||||
{
|
||||
_SongLog.Warning(exception, messageTemplate, propertyValues);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Error functions
|
||||
|
||||
/// <summary>
|
||||
/// Write an event with the Error level to the Error log.
|
||||
/// </summary>
|
||||
/// <param name="messageTemplate">Message template for this event.</param>
|
||||
/// <param name="callerMethodeName">Don't use! The methode name of the caller will be filled automatically by the compiler.</param>
|
||||
/// <param name="callerFilePath">Don't use! The filepath of the caller will be filled automatically by the compiler.</param>
|
||||
/// <param name="callerLineNumer">Don't use! The line number of the caller will be filled automatically by the compiler.</param>
|
||||
[MessageTemplateFormatMethod("messageTemplate")]
|
||||
public static void Error(string messageTemplate, [CallerMemberName] string callerMethodeName = "", [CallerFilePath] string callerFilePath = "", [CallerLineNumber] int callerLineNumer = -1)
|
||||
{
|
||||
using (LogContext.PushProperty("CallingContext", new { callerMethodeName, callerFilePath, callerLineNumer}))
|
||||
{
|
||||
_SongLog.Error(messageTemplate);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write an event with the Error level with additional propertyValues to the Error log.
|
||||
/// </summary>
|
||||
/// <param name="messageTemplate">Message template for this event.</param>
|
||||
/// <param name="propertyValues">Data inserted into the message template.</param>
|
||||
/// <param name="callerMethodeName">Don't use! The methode name of the caller will be filled automatically by the compiler.</param>
|
||||
/// <param name="callerFilePath">Don't use! The filepath of the caller will be filled automatically by the compiler.</param>
|
||||
/// <param name="callerLineNumer">Don't use! The line number of the caller will be filled automatically by the compiler.</param>
|
||||
[MessageTemplateFormatMethod("messageTemplate")]
|
||||
public static void Error(string messageTemplate, object[] propertyValues, [CallerMemberName] string callerMethodeName = "", [CallerFilePath] string callerFilePath = "", [CallerLineNumber] int callerLineNumer = -1)
|
||||
{
|
||||
using (LogContext.PushProperty("CallingContext", new { callerMethodeName, callerFilePath, callerLineNumer}))
|
||||
{
|
||||
_SongLog.Error(messageTemplate, propertyValues);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write an event with the Error level and associated exception to the Error log.
|
||||
/// </summary>
|
||||
/// <param name="exception">Exception of this event.</param>
|
||||
/// <param name="messageTemplate">Message template for this event.</param>
|
||||
/// <param name="callerMethodeName">Don't use! The methode name of the caller will be filled automatically by the compiler.</param>
|
||||
/// <param name="callerFilePath">Don't use! The filepath of the caller will be filled automatically by the compiler.</param>
|
||||
/// <param name="callerLineNumer">Don't use! The line number of the caller will be filled automatically by the compiler.</param>
|
||||
[MessageTemplateFormatMethod("messageTemplate")]
|
||||
public static void Error(Exception exception, string messageTemplate, [CallerMemberName] string callerMethodeName = "", [CallerFilePath] string callerFilePath = "", [CallerLineNumber] int callerLineNumer = -1)
|
||||
{
|
||||
using (LogContext.PushProperty("CallingContext", new { callerMethodeName, callerFilePath, callerLineNumer}))
|
||||
{
|
||||
_SongLog.Error( exception, messageTemplate);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write an event with the Error level with additional propertyValues and associated exception to the Error log.
|
||||
/// </summary>
|
||||
/// <param name="exception">Exception of this event.</param>
|
||||
/// <param name="messageTemplate">Message template for this event.</param>
|
||||
/// <param name="propertyValues">Data inserted into the message template.</param>
|
||||
/// <param name="callerMethodeName">Don't use! The methode name of the caller will be filled automatically by the compiler.</param>
|
||||
/// <param name="callerFilePath">Don't use! The filepath of the caller will be filled automatically by the compiler.</param>
|
||||
/// <param name="callerLineNumer">Don't use! The line number of the caller will be filled automatically by the compiler.</param>
|
||||
[MessageTemplateFormatMethod("messageTemplate")]
|
||||
public static void Error(Exception exception, string messageTemplate, object[] propertyValues, [CallerMemberName] string callerMethodeName = "", [CallerFilePath] string callerFilePath = "", [CallerLineNumber] int callerLineNumer = -1)
|
||||
{
|
||||
using (LogContext.PushProperty("CallingContext", new { callerMethodeName, callerFilePath, callerLineNumer}))
|
||||
{
|
||||
_SongLog.Error(exception, messageTemplate, propertyValues);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Fatal functions
|
||||
|
||||
/// <summary>
|
||||
/// Write an event with the Fatal level to the Fatal log.
|
||||
/// </summary>
|
||||
/// <param name="messageTemplate">Message template for this event.</param>
|
||||
/// <param name="callerMethodeName">Don't use! The methode name of the caller will be filled automatically by the compiler.</param>
|
||||
/// <param name="callerFilePath">Don't use! The filepath of the caller will be filled automatically by the compiler.</param>
|
||||
/// <param name="callerLineNumer">Don't use! The line number of the caller will be filled automatically by the compiler.</param>
|
||||
[MessageTemplateFormatMethod("messageTemplate")]
|
||||
public static void Fatal(string messageTemplate, [CallerMemberName] string callerMethodeName = "", [CallerFilePath] string callerFilePath = "", [CallerLineNumber] int callerLineNumer = -1)
|
||||
{
|
||||
using (LogContext.PushProperty("CallingContext", new { callerMethodeName, callerFilePath, callerLineNumer}))
|
||||
{
|
||||
_SongLog.Fatal(messageTemplate);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write an event with the Fatal level with additional propertyValues to the Fatal log.
|
||||
/// </summary>
|
||||
/// <param name="messageTemplate">Message template for this event.</param>
|
||||
/// <param name="propertyValues">Data inserted into the message template.</param>
|
||||
/// <param name="callerMethodeName">Don't use! The methode name of the caller will be filled automatically by the compiler.</param>
|
||||
/// <param name="callerFilePath">Don't use! The filepath of the caller will be filled automatically by the compiler.</param>
|
||||
/// <param name="callerLineNumer">Don't use! The line number of the caller will be filled automatically by the compiler.</param>
|
||||
[MessageTemplateFormatMethod("messageTemplate")]
|
||||
public static void Fatal(string messageTemplate, object[] propertyValues, [CallerMemberName] string callerMethodeName = "", [CallerFilePath] string callerFilePath = "", [CallerLineNumber] int callerLineNumer = -1)
|
||||
{
|
||||
using (LogContext.PushProperty("CallingContext", new { callerMethodeName, callerFilePath, callerLineNumer}))
|
||||
{
|
||||
_SongLog.Fatal(messageTemplate, propertyValues);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write an event with the Fatal level and associated exception to the Fatal log.
|
||||
/// </summary>
|
||||
/// <param name="exception">Exception of this event.</param>
|
||||
/// <param name="messageTemplate">Message template for this event.</param>
|
||||
/// <param name="callerMethodeName">Don't use! The methode name of the caller will be filled automatically by the compiler.</param>
|
||||
/// <param name="callerFilePath">Don't use! The filepath of the caller will be filled automatically by the compiler.</param>
|
||||
/// <param name="callerLineNumer">Don't use! The line number of the caller will be filled automatically by the compiler.</param>
|
||||
[MessageTemplateFormatMethod("messageTemplate")]
|
||||
public static void Fatal(Exception exception, string messageTemplate, [CallerMemberName] string callerMethodeName = "", [CallerFilePath] string callerFilePath = "", [CallerLineNumber] int callerLineNumer = -1)
|
||||
{
|
||||
using (LogContext.PushProperty("CallingContext", new { callerMethodeName, callerFilePath, callerLineNumer}))
|
||||
{
|
||||
_SongLog.Fatal( exception, messageTemplate);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write an event with the Fatal level with additional propertyValues and associated exception to the Fatal log.
|
||||
/// </summary>
|
||||
/// <param name="exception">Exception of this event.</param>
|
||||
/// <param name="messageTemplate">Message template for this event.</param>
|
||||
/// <param name="propertyValues">Data inserted into the message template.</param>
|
||||
/// <param name="callerMethodeName">Don't use! The methode name of the caller will be filled automatically by the compiler.</param>
|
||||
/// <param name="callerFilePath">Don't use! The filepath of the caller will be filled automatically by the compiler.</param>
|
||||
/// <param name="callerLineNumer">Don't use! The line number of the caller will be filled automatically by the compiler.</param>
|
||||
[MessageTemplateFormatMethod("messageTemplate")]
|
||||
public static void Fatal(Exception exception, string messageTemplate, object[] propertyValues, [CallerMemberName] string callerMethodeName = "", [CallerFilePath] string callerFilePath = "", [CallerLineNumber] int callerLineNumer = -1)
|
||||
{
|
||||
using (LogContext.PushProperty("CallingContext", new { callerMethodeName, callerFilePath, callerLineNumer}))
|
||||
{
|
||||
_SongLog.Fatal(exception, messageTemplate, propertyValues);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
<#@ template debug="false" hostspecific="false" language="C#" #>
|
||||
<#@ assembly name="System.Core" #>
|
||||
<#@ import namespace="System.Linq" #>
|
||||
<#@ import namespace="System.Text" #>
|
||||
<#@ import namespace="System.Collections.Generic" #>
|
||||
<#@ output extension=".cs" #>
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Runtime.CompilerServices;
|
||||
using Serilog.Context;
|
||||
using Serilog.Core;
|
||||
|
||||
namespace VocaluxeLib.Log
|
||||
{
|
||||
public static partial class CLog
|
||||
{
|
||||
|
||||
public static object[] Params(params object[] propertyValues)
|
||||
{
|
||||
return propertyValues;
|
||||
}
|
||||
|
||||
<# foreach (var Log in new[]{"Main","Song"}) { #>
|
||||
<# if(Log == "Song") { #>
|
||||
<# PushIndent(" "); #>
|
||||
|
||||
[SuppressMessage("ReSharper", "MemberHidesStaticFromOuterClass")]
|
||||
public static class CSongLog
|
||||
{
|
||||
<# } #>
|
||||
<# foreach (var LogLevel in new[]{"Verbose","Debug", "Information", "Warning", "Error", "Fatal"}) { #>
|
||||
|
||||
#region <#= LogLevel #> functions
|
||||
|
||||
/// <summary>
|
||||
/// Write an event with the <#= LogLevel #> level to the <#= LogLevel #> log.
|
||||
/// </summary>
|
||||
/// <param name="messageTemplate">Message template for this event.</param>
|
||||
<# if(Log == "Main") { #>
|
||||
/// <param name="show">True if an message should be shown to the user, false otherwise.</param>
|
||||
<# } #>
|
||||
/// <param name="callerMethodeName">Don't use! The methode name of the caller will be filled automatically by the compiler.</param>
|
||||
/// <param name="callerFilePath">Don't use! The filepath of the caller will be filled automatically by the compiler.</param>
|
||||
/// <param name="callerLineNumer">Don't use! The line number of the caller will be filled automatically by the compiler.</param>
|
||||
[MessageTemplateFormatMethod("messageTemplate")]
|
||||
public static void <#= LogLevel #>(string messageTemplate, <#= Log == "Main"?(LogLevel == "Fatal"?"bool show = true, ":"bool show = false, "):"" #>[CallerMemberName] string callerMethodeName = "", [CallerFilePath] string callerFilePath = "", [CallerLineNumber] int callerLineNumer = -1)
|
||||
{
|
||||
using (LogContext.PushProperty("CallingContext", new { callerMethodeName, callerFilePath, callerLineNumer}))
|
||||
{
|
||||
<#= Log == "Main"?"_MainLog":"_SongLog" #>.<#= LogLevel #>(messageTemplate);
|
||||
}
|
||||
<# if(Log == "Main") { #>
|
||||
if(show)
|
||||
_ShowLogAssistent(messageTemplate, null, callerMethodeName, callerFilePath, callerLineNumer);
|
||||
<# } #>
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write an event with the <#= LogLevel #> level with additional propertyValues to the <#= LogLevel #> log.
|
||||
/// </summary>
|
||||
/// <param name="messageTemplate">Message template for this event.</param>
|
||||
/// <param name="propertyValues">Data inserted into the message template.</param>
|
||||
<# if(Log == "Main") { #>
|
||||
/// <param name="show">True if an message should be shown to the user, false otherwise.</param>
|
||||
<# } #>
|
||||
/// <param name="callerMethodeName">Don't use! The methode name of the caller will be filled automatically by the compiler.</param>
|
||||
/// <param name="callerFilePath">Don't use! The filepath of the caller will be filled automatically by the compiler.</param>
|
||||
/// <param name="callerLineNumer">Don't use! The line number of the caller will be filled automatically by the compiler.</param>
|
||||
[MessageTemplateFormatMethod("messageTemplate")]
|
||||
public static void <#= LogLevel #>(string messageTemplate, object[] propertyValues, <#= Log == "Main"?(LogLevel == "Fatal"?"bool show = true, ":"bool show = false, "):"" #>[CallerMemberName] string callerMethodeName = "", [CallerFilePath] string callerFilePath = "", [CallerLineNumber] int callerLineNumer = -1)
|
||||
{
|
||||
using (LogContext.PushProperty("CallingContext", new { callerMethodeName, callerFilePath, callerLineNumer}))
|
||||
{
|
||||
<#= Log == "Main"?"_MainLog":"_SongLog" #>.<#= LogLevel #>(messageTemplate, propertyValues);
|
||||
}
|
||||
<# if(Log == "Main") { #>
|
||||
if(show)
|
||||
_ShowLogAssistent(messageTemplate, propertyValues, callerMethodeName, callerFilePath, callerLineNumer);
|
||||
<# } #>
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write an event with the <#= LogLevel #> level and associated exception to the <#= LogLevel #> log.
|
||||
/// </summary>
|
||||
/// <param name="exception">Exception of this event.</param>
|
||||
/// <param name="messageTemplate">Message template for this event.</param>
|
||||
<# if(Log == "Main") { #>
|
||||
/// <param name="show">True if an message should be shown to the user, false otherwise.</param>
|
||||
<# } #>
|
||||
/// <param name="callerMethodeName">Don't use! The methode name of the caller will be filled automatically by the compiler.</param>
|
||||
/// <param name="callerFilePath">Don't use! The filepath of the caller will be filled automatically by the compiler.</param>
|
||||
/// <param name="callerLineNumer">Don't use! The line number of the caller will be filled automatically by the compiler.</param>
|
||||
[MessageTemplateFormatMethod("messageTemplate")]
|
||||
public static void <#= LogLevel #>(Exception exception, string messageTemplate, <#= Log == "Main"?(LogLevel == "Fatal"?"bool show = true, ":"bool show = false, "):"" #>[CallerMemberName] string callerMethodeName = "", [CallerFilePath] string callerFilePath = "", [CallerLineNumber] int callerLineNumer = -1)
|
||||
{
|
||||
using (LogContext.PushProperty("CallingContext", new { callerMethodeName, callerFilePath, callerLineNumer}))
|
||||
{
|
||||
<#= Log == "Main"?"_MainLog":"_SongLog" #>.<#= LogLevel #>( exception, messageTemplate);
|
||||
}
|
||||
<# if(Log == "Main") { #>
|
||||
if(show)
|
||||
_ShowLogAssistent(messageTemplate, null, callerMethodeName, callerFilePath, callerLineNumer);
|
||||
<# } #>
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write an event with the <#= LogLevel #> level with additional propertyValues and associated exception to the <#= LogLevel #> log.
|
||||
/// </summary>
|
||||
/// <param name="exception">Exception of this event.</param>
|
||||
/// <param name="messageTemplate">Message template for this event.</param>
|
||||
/// <param name="propertyValues">Data inserted into the message template.</param>
|
||||
<# if(Log == "Main") { #>
|
||||
/// <param name="show">True if an message should be shown to the user, false otherwise.</param>
|
||||
<# } #>
|
||||
/// <param name="callerMethodeName">Don't use! The methode name of the caller will be filled automatically by the compiler.</param>
|
||||
/// <param name="callerFilePath">Don't use! The filepath of the caller will be filled automatically by the compiler.</param>
|
||||
/// <param name="callerLineNumer">Don't use! The line number of the caller will be filled automatically by the compiler.</param>
|
||||
[MessageTemplateFormatMethod("messageTemplate")]
|
||||
public static void <#= LogLevel #>(Exception exception, string messageTemplate, object[] propertyValues, <#= Log == "Main"?(LogLevel == "Fatal"?"bool show = true, ":"bool show = false, "):"" #>[CallerMemberName] string callerMethodeName = "", [CallerFilePath] string callerFilePath = "", [CallerLineNumber] int callerLineNumer = -1)
|
||||
{
|
||||
using (LogContext.PushProperty("CallingContext", new { callerMethodeName, callerFilePath, callerLineNumer}))
|
||||
{
|
||||
<#= Log == "Main"?"_MainLog":"_SongLog" #>.<#= LogLevel #>(exception, messageTemplate, propertyValues);
|
||||
}
|
||||
<# if(Log == "Main") { #>
|
||||
if(show)
|
||||
_ShowLogAssistent(messageTemplate, propertyValues, callerMethodeName, callerFilePath, callerLineNumer);
|
||||
<# } #>
|
||||
}
|
||||
|
||||
#endregion
|
||||
<# } #>
|
||||
<# if(Log == "Song") { #>
|
||||
<# PopIndent(); #>
|
||||
}
|
||||
<# } #>
|
||||
<# } #>
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using Serilog;
|
||||
using Serilog.Configuration;
|
||||
using Serilog.Core;
|
||||
using Serilog.Events;
|
||||
|
||||
namespace VocaluxeLib.Log.Enricher
|
||||
{
|
||||
public static class WithTimeStampFromStartExtension
|
||||
{
|
||||
// ReSharper disable once InconsistentNaming
|
||||
public static LoggerConfiguration WithTimeStampFromStart(this LoggerEnrichmentConfiguration enrich)
|
||||
{
|
||||
return enrich.With(new CTimeStampFromStartEnricher());
|
||||
}
|
||||
|
||||
private class CTimeStampFromStartEnricher : ILogEventEnricher
|
||||
{
|
||||
private readonly DateTimeOffset _Start = DateTimeOffset.Now;
|
||||
|
||||
public void Enrich(LogEvent logEvent, ILogEventPropertyFactory lepf)
|
||||
{
|
||||
logEvent.AddPropertyIfAbsent(
|
||||
lepf.CreateProperty("TimeStampFromStart", logEvent.Timestamp - _Start));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace VocaluxeLib.Log.Rolling
|
||||
{
|
||||
static class LogFileRoller
|
||||
{
|
||||
public static void RollLogs(string mainLogFile, int numLogsToKeep)
|
||||
{
|
||||
_DeleteOldLogs(mainLogFile, numLogsToKeep);
|
||||
|
||||
string currentSourceFile = _GenerateRollLogFileName(mainLogFile, numLogsToKeep);
|
||||
|
||||
|
||||
for (var i = numLogsToKeep; i > 1; i--)
|
||||
{
|
||||
string currentTargetFile = currentSourceFile;
|
||||
currentSourceFile = _GenerateRollLogFileName(mainLogFile, i - 1);
|
||||
|
||||
if (File.Exists(currentSourceFile))
|
||||
{
|
||||
try
|
||||
{
|
||||
File.Move(currentSourceFile, currentTargetFile);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
// Cant log anything here as the log isn't initialized yet
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (File.Exists(mainLogFile))
|
||||
{
|
||||
try
|
||||
{
|
||||
if (numLogsToKeep > 0)
|
||||
File.Move(mainLogFile, currentSourceFile);
|
||||
else
|
||||
File.Delete(mainLogFile);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
// Cant log anything here as the log isn't initialized yet
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void _DeleteOldLogs(string mainLogFile, int numLogsToKeep)
|
||||
{
|
||||
Regex r = new Regex($"{Path.GetDirectoryName(mainLogFile)}\\\\{Path.GetFileNameWithoutExtension(mainLogFile)}_([0-9]+){Path.GetExtension(mainLogFile)}", RegexOptions.IgnoreCase);
|
||||
IEnumerable<string> logFiles = Directory.EnumerateFiles($"{Path.GetDirectoryName(mainLogFile)}", $"{Path.GetFileNameWithoutExtension(mainLogFile)}*{Path.GetExtension(mainLogFile)}");
|
||||
foreach (string file in logFiles)
|
||||
{
|
||||
Match m = r.Match(file);
|
||||
if (m.Success)
|
||||
{
|
||||
int logNum = -1;
|
||||
Int32.TryParse(m.Groups[1].Value, out logNum);
|
||||
|
||||
if (logNum < 0 || logNum > numLogsToKeep - 1)
|
||||
{
|
||||
try
|
||||
{
|
||||
File.Delete(file);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
// Cant log anything here as the log isn't initialized yet
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static string _GenerateRollLogFileName(string mainLogFile, int number)
|
||||
{
|
||||
return $"{Path.GetDirectoryName(mainLogFile)}\\{Path.GetFileNameWithoutExtension(mainLogFile)}_{number}{Path.GetExtension(mainLogFile)}";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,355 @@
|
||||
// From https://github.com/serilog/serilog/blob/4736691b7a0cd574e178c24a61caa8a9196a6a61/src/Serilog/Core/Pipeline/SilentLogger.cs
|
||||
|
||||
// Copyright 2013-2015 Serilog Contributors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Serilog;
|
||||
using Serilog.Core;
|
||||
using Serilog.Events;
|
||||
|
||||
namespace VocaluxeLib.Log.Serilog
|
||||
{
|
||||
class SilentLogger : ILogger
|
||||
{
|
||||
public ILogger ForContext(ILogEventEnricher enricher)
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
public ILogger ForContext(IEnumerable<ILogEventEnricher> enrichers)
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
public ILogger ForContext(string propertyName, object value, bool destructureObjects = false)
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
public ILogger ForContext<TSource>()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
public ILogger ForContext(Type source)
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
public void Write(LogEvent logEvent)
|
||||
{
|
||||
}
|
||||
|
||||
public void Write(LogEventLevel level, string messageTemplate)
|
||||
{
|
||||
}
|
||||
|
||||
public void Write<T>(LogEventLevel level, string messageTemplate, T propertyValue)
|
||||
{
|
||||
}
|
||||
|
||||
public void Write<T0, T1>(LogEventLevel level, string messageTemplate, T0 propertyValue0, T1 propertyValue1)
|
||||
{
|
||||
}
|
||||
|
||||
public void Write<T0, T1, T2>(LogEventLevel level, string messageTemplate, T0 propertyValue0, T1 propertyValue1, T2 propertyValue2)
|
||||
{
|
||||
}
|
||||
|
||||
public void Write(LogEventLevel level, string messageTemplate, params object[] propertyValues)
|
||||
{
|
||||
}
|
||||
|
||||
public void Write(LogEventLevel level, Exception exception, string messageTemplate)
|
||||
{
|
||||
}
|
||||
|
||||
public void Write<T>(LogEventLevel level, Exception exception, string messageTemplate, T propertyValue)
|
||||
{
|
||||
}
|
||||
|
||||
public void Write<T0, T1>(LogEventLevel level, Exception exception, string messageTemplate, T0 propertyValue0, T1 propertyValue1)
|
||||
{
|
||||
}
|
||||
|
||||
public void Write<T0, T1, T2>(LogEventLevel level, Exception exception, string messageTemplate, T0 propertyValue0, T1 propertyValue1, T2 propertyValue2)
|
||||
{
|
||||
}
|
||||
|
||||
public void Write(LogEventLevel level, Exception exception, string messageTemplate, params object[] propertyValues)
|
||||
{
|
||||
}
|
||||
|
||||
public bool IsEnabled(LogEventLevel level)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public void Verbose(string messageTemplate)
|
||||
{
|
||||
}
|
||||
|
||||
public void Verbose<T>(string messageTemplate, T propertyValue)
|
||||
{
|
||||
}
|
||||
|
||||
public void Verbose<T0, T1>(string messageTemplate, T0 propertyValue0, T1 propertyValue1)
|
||||
{
|
||||
}
|
||||
|
||||
public void Verbose<T0, T1, T2>(string messageTemplate, T0 propertyValue0, T1 propertyValue1, T2 propertyValue2)
|
||||
{
|
||||
}
|
||||
|
||||
public void Verbose(string messageTemplate, params object[] propertyValues)
|
||||
{
|
||||
}
|
||||
|
||||
public void Verbose(Exception exception, string messageTemplate)
|
||||
{
|
||||
}
|
||||
|
||||
public void Verbose<T>(Exception exception, string messageTemplate, T propertyValue)
|
||||
{
|
||||
}
|
||||
|
||||
public void Verbose<T0, T1>(Exception exception, string messageTemplate, T0 propertyValue0, T1 propertyValue1)
|
||||
{
|
||||
}
|
||||
|
||||
public void Verbose<T0, T1, T2>(Exception exception, string messageTemplate, T0 propertyValue0, T1 propertyValue1, T2 propertyValue2)
|
||||
{
|
||||
}
|
||||
|
||||
public void Verbose(Exception exception, string messageTemplate, params object[] propertyValues)
|
||||
{
|
||||
}
|
||||
|
||||
public void Debug(string messageTemplate)
|
||||
{
|
||||
}
|
||||
|
||||
public void Debug<T>(string messageTemplate, T propertyValue)
|
||||
{
|
||||
}
|
||||
|
||||
public void Debug<T0, T1>(string messageTemplate, T0 propertyValue0, T1 propertyValue1)
|
||||
{
|
||||
}
|
||||
|
||||
public void Debug<T0, T1, T2>(string messageTemplate, T0 propertyValue0, T1 propertyValue1, T2 propertyValue2)
|
||||
{
|
||||
}
|
||||
|
||||
public void Debug(string messageTemplate, params object[] propertyValues)
|
||||
{
|
||||
}
|
||||
|
||||
public void Debug(Exception exception, string messageTemplate)
|
||||
{
|
||||
}
|
||||
|
||||
public void Debug<T>(Exception exception, string messageTemplate, T propertyValue)
|
||||
{
|
||||
}
|
||||
|
||||
public void Debug<T0, T1>(Exception exception, string messageTemplate, T0 propertyValue0, T1 propertyValue1)
|
||||
{
|
||||
}
|
||||
|
||||
public void Debug<T0, T1, T2>(Exception exception, string messageTemplate, T0 propertyValue0, T1 propertyValue1, T2 propertyValue2)
|
||||
{
|
||||
}
|
||||
|
||||
public void Debug(Exception exception, string messageTemplate, params object[] propertyValues)
|
||||
{
|
||||
}
|
||||
|
||||
public void Information(string messageTemplate)
|
||||
{
|
||||
}
|
||||
|
||||
public void Information<T>(string messageTemplate, T propertyValue)
|
||||
{
|
||||
}
|
||||
|
||||
public void Information<T0, T1>(string messageTemplate, T0 propertyValue0, T1 propertyValue1)
|
||||
{
|
||||
}
|
||||
|
||||
public void Information<T0, T1, T2>(string messageTemplate, T0 propertyValue0, T1 propertyValue1, T2 propertyValue2)
|
||||
{
|
||||
}
|
||||
|
||||
public void Information(string messageTemplate, params object[] propertyValues)
|
||||
{
|
||||
}
|
||||
|
||||
public void Information(Exception exception, string messageTemplate)
|
||||
{
|
||||
}
|
||||
|
||||
public void Information<T>(Exception exception, string messageTemplate, T propertyValue)
|
||||
{
|
||||
}
|
||||
|
||||
public void Information<T0, T1>(Exception exception, string messageTemplate, T0 propertyValue0, T1 propertyValue1)
|
||||
{
|
||||
}
|
||||
|
||||
public void Information<T0, T1, T2>(Exception exception, string messageTemplate, T0 propertyValue0, T1 propertyValue1, T2 propertyValue2)
|
||||
{
|
||||
}
|
||||
|
||||
public void Information(Exception exception, string messageTemplate, params object[] propertyValues)
|
||||
{
|
||||
}
|
||||
|
||||
public void Warning(string messageTemplate)
|
||||
{
|
||||
}
|
||||
|
||||
public void Warning<T>(string messageTemplate, T propertyValue)
|
||||
{
|
||||
}
|
||||
|
||||
public void Warning<T0, T1>(string messageTemplate, T0 propertyValue0, T1 propertyValue1)
|
||||
{
|
||||
}
|
||||
|
||||
public void Warning<T0, T1, T2>(string messageTemplate, T0 propertyValue0, T1 propertyValue1, T2 propertyValue2)
|
||||
{
|
||||
}
|
||||
|
||||
public void Warning(string messageTemplate, params object[] propertyValues)
|
||||
{
|
||||
}
|
||||
|
||||
public void Warning(Exception exception, string messageTemplate)
|
||||
{
|
||||
}
|
||||
|
||||
public void Warning<T>(Exception exception, string messageTemplate, T propertyValue)
|
||||
{
|
||||
}
|
||||
|
||||
public void Warning<T0, T1>(Exception exception, string messageTemplate, T0 propertyValue0, T1 propertyValue1)
|
||||
{
|
||||
}
|
||||
|
||||
public void Warning<T0, T1, T2>(Exception exception, string messageTemplate, T0 propertyValue0, T1 propertyValue1, T2 propertyValue2)
|
||||
{
|
||||
}
|
||||
|
||||
public void Warning(Exception exception, string messageTemplate, params object[] propertyValues)
|
||||
{
|
||||
}
|
||||
|
||||
public void Error(string messageTemplate)
|
||||
{
|
||||
}
|
||||
|
||||
public void Error<T>(string messageTemplate, T propertyValue)
|
||||
{
|
||||
}
|
||||
|
||||
public void Error<T0, T1>(string messageTemplate, T0 propertyValue0, T1 propertyValue1)
|
||||
{
|
||||
}
|
||||
|
||||
public void Error<T0, T1, T2>(string messageTemplate, T0 propertyValue0, T1 propertyValue1, T2 propertyValue2)
|
||||
{
|
||||
}
|
||||
|
||||
public void Error(string messageTemplate, params object[] propertyValues)
|
||||
{
|
||||
}
|
||||
|
||||
public void Error(Exception exception, string messageTemplate)
|
||||
{
|
||||
}
|
||||
|
||||
public void Error<T>(Exception exception, string messageTemplate, T propertyValue)
|
||||
{
|
||||
}
|
||||
|
||||
public void Error<T0, T1>(Exception exception, string messageTemplate, T0 propertyValue0, T1 propertyValue1)
|
||||
{
|
||||
}
|
||||
|
||||
public void Error<T0, T1, T2>(Exception exception, string messageTemplate, T0 propertyValue0, T1 propertyValue1, T2 propertyValue2)
|
||||
{
|
||||
}
|
||||
|
||||
public void Error(Exception exception, string messageTemplate, params object[] propertyValues)
|
||||
{
|
||||
}
|
||||
|
||||
public void Fatal(string messageTemplate)
|
||||
{
|
||||
}
|
||||
|
||||
public void Fatal<T>(string messageTemplate, T propertyValue)
|
||||
{
|
||||
}
|
||||
|
||||
public void Fatal<T0, T1>(string messageTemplate, T0 propertyValue0, T1 propertyValue1)
|
||||
{
|
||||
}
|
||||
|
||||
public void Fatal<T0, T1, T2>(string messageTemplate, T0 propertyValue0, T1 propertyValue1, T2 propertyValue2)
|
||||
{
|
||||
}
|
||||
|
||||
public void Fatal(string messageTemplate, params object[] propertyValues)
|
||||
{
|
||||
}
|
||||
|
||||
public void Fatal(Exception exception, string messageTemplate)
|
||||
{
|
||||
}
|
||||
|
||||
public void Fatal<T>(Exception exception, string messageTemplate, T propertyValue)
|
||||
{
|
||||
}
|
||||
|
||||
public void Fatal<T0, T1>(Exception exception, string messageTemplate, T0 propertyValue0, T1 propertyValue1)
|
||||
{
|
||||
}
|
||||
|
||||
public void Fatal<T0, T1, T2>(Exception exception, string messageTemplate, T0 propertyValue0, T1 propertyValue1, T2 propertyValue2)
|
||||
{
|
||||
}
|
||||
|
||||
public void Fatal(Exception exception, string messageTemplate, params object[] propertyValues)
|
||||
{
|
||||
}
|
||||
|
||||
[MessageTemplateFormatMethod("messageTemplate")]
|
||||
public bool BindMessageTemplate(string messageTemplate, object[] propertyValues, out MessageTemplate parsedTemplate, out IEnumerable<LogEventProperty> boundProperties)
|
||||
{
|
||||
parsedTemplate = null;
|
||||
boundProperties = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool BindProperty(string propertyName, object value, bool destructureObjects, out LogEventProperty property)
|
||||
{
|
||||
property = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user