Files
Vocaluxe/VocaluxeLib/Log/CLogFunctions.tt
T
2018-01-16 11:57:15 +01:00

139 lines
7.7 KiB
Plaintext

<#@ 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(); #>
}
<# } #>
<# } #>
}
}