From e236535a428bb085939a89f92096a7c3ddd0c445 Mon Sep 17 00:00:00 2001 From: lukeIam <2lukeiam@gmail.com> Date: Wed, 17 Jan 2018 17:57:36 +0100 Subject: [PATCH] Fatal is now the new "error + terminate application" --- VocaluxeLib/Log/CLogFunctions.cs | 96 +++++++------------------------- VocaluxeLib/Log/CLogFunctions.tt | 33 +++++++++-- 2 files changed, 49 insertions(+), 80 deletions(-) diff --git a/VocaluxeLib/Log/CLogFunctions.cs b/VocaluxeLib/Log/CLogFunctions.cs index cf311403..d241cc4c 100644 --- a/VocaluxeLib/Log/CLogFunctions.cs +++ b/VocaluxeLib/Log/CLogFunctions.cs @@ -438,7 +438,7 @@ namespace VocaluxeLib.Log #region Fatal functions /// - /// Write an event with the Fatal level to the Fatal log. + /// Write an event with the Fatal level to the Fatal log and TERMINATES the appication. /// /// Message template for this event. /// True if an message should be shown to the user, false otherwise. @@ -454,10 +454,14 @@ namespace VocaluxeLib.Log } if(show) _ShowLogAssistent(messageTemplate, null, callerMethodeName, callerFilePath, callerLineNumer); + + // Close logs and exit + Close(); + Environment.Exit(Environment.ExitCode); } /// - /// Write an event with the Fatal level with additional propertyValues to the Fatal log. + /// Write an event with the Fatal level with additional propertyValues to the Fatal log and TERMINATES the appication. /// /// Message template for this event. /// Data inserted into the message template. @@ -474,10 +478,14 @@ namespace VocaluxeLib.Log } if(show) _ShowLogAssistent(messageTemplate, propertyValues, callerMethodeName, callerFilePath, callerLineNumer); + + // Close logs and exit + Close(); + Environment.Exit(Environment.ExitCode); } /// - /// Write an event with the Fatal level and associated exception to the Fatal log. + /// Write an event with the Fatal level and associated exception to the Fatal log and TERMINATES the appication. /// /// Exception of this event. /// Message template for this event. @@ -494,10 +502,14 @@ namespace VocaluxeLib.Log } if(show) _ShowLogAssistent(messageTemplate, null, callerMethodeName, callerFilePath, callerLineNumer); + + // Close logs and exit + Close(); + Environment.Exit(Environment.ExitCode); } /// - /// Write an event with the Fatal level with additional propertyValues and associated exception to the Fatal log. + /// Write an event with the Fatal level with additional propertyValues and associated exception to the Fatal log and TERMINATES the appication. /// /// Exception of this event. /// Message template for this event. @@ -515,6 +527,10 @@ namespace VocaluxeLib.Log } if(show) _ShowLogAssistent(messageTemplate, propertyValues, callerMethodeName, callerFilePath, callerLineNumer); + + // Close logs and exit + Close(); + Environment.Exit(Environment.ExitCode); } #endregion @@ -882,78 +898,6 @@ namespace VocaluxeLib.Log } #endregion - - #region Fatal functions - - /// - /// Write an event with the Fatal level to the Fatal log. - /// - /// Message template for this event. - /// Don't use! The methode name of the caller will be filled automatically by the compiler. - /// Don't use! The filepath of the caller will be filled automatically by the compiler. - /// Don't use! The line number of the caller will be filled automatically by the compiler. - [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); - } - } - - /// - /// Write an event with the Fatal level with additional propertyValues to the Fatal log. - /// - /// Message template for this event. - /// Data inserted into the message template. - /// Don't use! The methode name of the caller will be filled automatically by the compiler. - /// Don't use! The filepath of the caller will be filled automatically by the compiler. - /// Don't use! The line number of the caller will be filled automatically by the compiler. - [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); - } - } - - /// - /// Write an event with the Fatal level and associated exception to the Fatal log. - /// - /// Exception of this event. - /// Message template for this event. - /// Don't use! The methode name of the caller will be filled automatically by the compiler. - /// Don't use! The filepath of the caller will be filled automatically by the compiler. - /// Don't use! The line number of the caller will be filled automatically by the compiler. - [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); - } - } - - /// - /// Write an event with the Fatal level with additional propertyValues and associated exception to the Fatal log. - /// - /// Exception of this event. - /// Message template for this event. - /// Data inserted into the message template. - /// Don't use! The methode name of the caller will be filled automatically by the compiler. - /// Don't use! The filepath of the caller will be filled automatically by the compiler. - /// Don't use! The line number of the caller will be filled automatically by the compiler. - [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 } } } \ No newline at end of file diff --git a/VocaluxeLib/Log/CLogFunctions.tt b/VocaluxeLib/Log/CLogFunctions.tt index 2fe5ec71..1f49063c 100644 --- a/VocaluxeLib/Log/CLogFunctions.tt +++ b/VocaluxeLib/Log/CLogFunctions.tt @@ -29,11 +29,12 @@ namespace VocaluxeLib.Log { <# } #> <# foreach (var LogLevel in new[]{"Verbose","Debug", "Information", "Warning", "Error", "Fatal"}) { #> +<# if(LogLevel == "Fatal" && Log == "Song") continue; #> #region <#= LogLevel #> functions /// - /// Write an event with the <#= LogLevel #> level to the <#= LogLevel #> log. + /// Write an event with the <#= LogLevel #> level to the <#= LogLevel #> log<#= LogLevel == "Fatal"?" and TERMINATES the appication":"" #>. /// /// Message template for this event. <# if(Log == "Main") { #> @@ -52,11 +53,17 @@ namespace VocaluxeLib.Log <# if(Log == "Main") { #> if(show) _ShowLogAssistent(messageTemplate, null, callerMethodeName, callerFilePath, callerLineNumer); +<# } #> +<# if(LogLevel == "Fatal") { #> + + // Close logs and exit + Close(); + Environment.Exit(Environment.ExitCode); <# } #> } /// - /// Write an event with the <#= LogLevel #> level with additional propertyValues to the <#= LogLevel #> log. + /// Write an event with the <#= LogLevel #> level with additional propertyValues to the <#= LogLevel #> log<#= LogLevel == "Fatal"?" and TERMINATES the appication":"" #>. /// /// Message template for this event. /// Data inserted into the message template. @@ -76,11 +83,17 @@ namespace VocaluxeLib.Log <# if(Log == "Main") { #> if(show) _ShowLogAssistent(messageTemplate, propertyValues, callerMethodeName, callerFilePath, callerLineNumer); +<# } #> +<# if(LogLevel == "Fatal") { #> + + // Close logs and exit + Close(); + Environment.Exit(Environment.ExitCode); <# } #> } /// - /// Write an event with the <#= LogLevel #> level and associated exception to the <#= LogLevel #> log. + /// Write an event with the <#= LogLevel #> level and associated exception to the <#= LogLevel #> log<#= LogLevel == "Fatal"?" and TERMINATES the appication":"" #>. /// /// Exception of this event. /// Message template for this event. @@ -100,11 +113,17 @@ namespace VocaluxeLib.Log <# if(Log == "Main") { #> if(show) _ShowLogAssistent(messageTemplate, null, callerMethodeName, callerFilePath, callerLineNumer); +<# } #> +<# if(LogLevel == "Fatal") { #> + + // Close logs and exit + Close(); + Environment.Exit(Environment.ExitCode); <# } #> } /// - /// Write an event with the <#= LogLevel #> level with additional propertyValues and associated exception to the <#= LogLevel #> log. + /// Write an event with the <#= LogLevel #> level with additional propertyValues and associated exception to the <#= LogLevel #> log<#= LogLevel == "Fatal"?" and TERMINATES the appication":"" #>. /// /// Exception of this event. /// Message template for this event. @@ -125,6 +144,12 @@ namespace VocaluxeLib.Log <# if(Log == "Main") { #> if(show) _ShowLogAssistent(messageTemplate, propertyValues, callerMethodeName, callerFilePath, callerLineNumer); +<# } #> +<# if(LogLevel == "Fatal") { #> + + // Close logs and exit + Close(); + Environment.Exit(Environment.ExitCode); <# } #> }