Fix: Additional properties are ignored

This commit is contained in:
lukeIam committed 2018-01-28 14:17:47 +01:00
1 parent 7f2f5dd2d2
commit 5b61bc4bd2
3 files changed
+320 -26

No files matched your search

+2 -2
View File
@@ -111,8 +111,8 @@ namespace VocaluxeLib.Log
#endif #endif
.CreateLogger(); .CreateLogger();
// Adding fist line to log with information about this run // Adding first line to log with information about this run
Information("Starting to log", Params( new { Version = _CurrentVersion, StartDate = DateTime.Now, Id = Guid.NewGuid() } ) ); Information("Starting to log", Params( new { Version = _CurrentVersion}, new { StartDate = DateTime.Now}, new { Id = Guid.NewGuid() } ) );
} }
/// <summary> /// <summary>
+289 -22
View File
@@ -17,7 +17,9 @@
using System; using System;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Text.RegularExpressions;
using Serilog.Context; using Serilog.Context;
using Serilog.Core; using Serilog.Core;
@@ -25,6 +27,7 @@ namespace VocaluxeLib.Log
{ {
public static partial class CLog public static partial class CLog
{ {
private static Regex _PropertiesRegex = new Regex("{[^}]+}");
public static object[] Params(params object[] propertyValues) public static object[] Params(params object[] propertyValues)
{ {
@@ -67,7 +70,19 @@ namespace VocaluxeLib.Log
{ {
using (LogContext.PushProperty("CallingContext", new { callerMethodeName, callerFilePath, callerLineNumer})) using (LogContext.PushProperty("CallingContext", new { callerMethodeName, callerFilePath, callerLineNumer}))
{ {
_MainLog.Verbose(messageTemplate, propertyValues); int usedPropertiesCount = _PropertiesRegex.Matches(messageTemplate).Cast<Match>().Select(m => m.Value).Distinct().Count();
if (propertyValues.Length > usedPropertiesCount)
{
using (LogContext.PushProperty("AdditionalData", propertyValues.Skip(usedPropertiesCount)))
{
_MainLog.Verbose(messageTemplate, propertyValues);
}
}
else
{
_MainLog.Verbose(messageTemplate, propertyValues);
}
} }
if(show) if(show)
ShowLogAssistant(messageTemplate, propertyValues); ShowLogAssistant(messageTemplate, propertyValues);
@@ -108,7 +123,19 @@ namespace VocaluxeLib.Log
{ {
using (LogContext.PushProperty("CallingContext", new { callerMethodeName, callerFilePath, callerLineNumer})) using (LogContext.PushProperty("CallingContext", new { callerMethodeName, callerFilePath, callerLineNumer}))
{ {
_MainLog.Verbose(exception, messageTemplate, propertyValues); int usedPropertiesCount = _PropertiesRegex.Matches(messageTemplate).Cast<Match>().Select(m => m.Value).Distinct().Count();
if (propertyValues.Length > usedPropertiesCount)
{
using (LogContext.PushProperty("AdditionalData", propertyValues.Skip(usedPropertiesCount)))
{
_MainLog.Verbose(exception, messageTemplate, propertyValues);
}
}
else
{
_MainLog.Verbose(exception, messageTemplate, propertyValues);
}
} }
if(show) if(show)
ShowLogAssistant(messageTemplate, propertyValues); ShowLogAssistant(messageTemplate, propertyValues);
@@ -151,7 +178,19 @@ namespace VocaluxeLib.Log
{ {
using (LogContext.PushProperty("CallingContext", new { callerMethodeName, callerFilePath, callerLineNumer})) using (LogContext.PushProperty("CallingContext", new { callerMethodeName, callerFilePath, callerLineNumer}))
{ {
_MainLog.Debug(messageTemplate, propertyValues); int usedPropertiesCount = _PropertiesRegex.Matches(messageTemplate).Cast<Match>().Select(m => m.Value).Distinct().Count();
if (propertyValues.Length > usedPropertiesCount)
{
using (LogContext.PushProperty("AdditionalData", propertyValues.Skip(usedPropertiesCount)))
{
_MainLog.Debug(messageTemplate, propertyValues);
}
}
else
{
_MainLog.Debug(messageTemplate, propertyValues);
}
} }
if(show) if(show)
ShowLogAssistant(messageTemplate, propertyValues); ShowLogAssistant(messageTemplate, propertyValues);
@@ -192,7 +231,19 @@ namespace VocaluxeLib.Log
{ {
using (LogContext.PushProperty("CallingContext", new { callerMethodeName, callerFilePath, callerLineNumer})) using (LogContext.PushProperty("CallingContext", new { callerMethodeName, callerFilePath, callerLineNumer}))
{ {
_MainLog.Debug(exception, messageTemplate, propertyValues); int usedPropertiesCount = _PropertiesRegex.Matches(messageTemplate).Cast<Match>().Select(m => m.Value).Distinct().Count();
if (propertyValues.Length > usedPropertiesCount)
{
using (LogContext.PushProperty("AdditionalData", propertyValues.Skip(usedPropertiesCount)))
{
_MainLog.Debug(exception, messageTemplate, propertyValues);
}
}
else
{
_MainLog.Debug(exception, messageTemplate, propertyValues);
}
} }
if(show) if(show)
ShowLogAssistant(messageTemplate, propertyValues); ShowLogAssistant(messageTemplate, propertyValues);
@@ -235,7 +286,19 @@ namespace VocaluxeLib.Log
{ {
using (LogContext.PushProperty("CallingContext", new { callerMethodeName, callerFilePath, callerLineNumer})) using (LogContext.PushProperty("CallingContext", new { callerMethodeName, callerFilePath, callerLineNumer}))
{ {
_MainLog.Information(messageTemplate, propertyValues); int usedPropertiesCount = _PropertiesRegex.Matches(messageTemplate).Cast<Match>().Select(m => m.Value).Distinct().Count();
if (propertyValues.Length > usedPropertiesCount)
{
using (LogContext.PushProperty("AdditionalData", propertyValues.Skip(usedPropertiesCount)))
{
_MainLog.Information(messageTemplate, propertyValues);
}
}
else
{
_MainLog.Information(messageTemplate, propertyValues);
}
} }
if(show) if(show)
ShowLogAssistant(messageTemplate, propertyValues); ShowLogAssistant(messageTemplate, propertyValues);
@@ -276,7 +339,19 @@ namespace VocaluxeLib.Log
{ {
using (LogContext.PushProperty("CallingContext", new { callerMethodeName, callerFilePath, callerLineNumer})) using (LogContext.PushProperty("CallingContext", new { callerMethodeName, callerFilePath, callerLineNumer}))
{ {
_MainLog.Information(exception, messageTemplate, propertyValues); int usedPropertiesCount = _PropertiesRegex.Matches(messageTemplate).Cast<Match>().Select(m => m.Value).Distinct().Count();
if (propertyValues.Length > usedPropertiesCount)
{
using (LogContext.PushProperty("AdditionalData", propertyValues.Skip(usedPropertiesCount)))
{
_MainLog.Information(exception, messageTemplate, propertyValues);
}
}
else
{
_MainLog.Information(exception, messageTemplate, propertyValues);
}
} }
if(show) if(show)
ShowLogAssistant(messageTemplate, propertyValues); ShowLogAssistant(messageTemplate, propertyValues);
@@ -319,7 +394,19 @@ namespace VocaluxeLib.Log
{ {
using (LogContext.PushProperty("CallingContext", new { callerMethodeName, callerFilePath, callerLineNumer})) using (LogContext.PushProperty("CallingContext", new { callerMethodeName, callerFilePath, callerLineNumer}))
{ {
_MainLog.Warning(messageTemplate, propertyValues); int usedPropertiesCount = _PropertiesRegex.Matches(messageTemplate).Cast<Match>().Select(m => m.Value).Distinct().Count();
if (propertyValues.Length > usedPropertiesCount)
{
using (LogContext.PushProperty("AdditionalData", propertyValues.Skip(usedPropertiesCount)))
{
_MainLog.Warning(messageTemplate, propertyValues);
}
}
else
{
_MainLog.Warning(messageTemplate, propertyValues);
}
} }
if(show) if(show)
ShowLogAssistant(messageTemplate, propertyValues); ShowLogAssistant(messageTemplate, propertyValues);
@@ -360,7 +447,19 @@ namespace VocaluxeLib.Log
{ {
using (LogContext.PushProperty("CallingContext", new { callerMethodeName, callerFilePath, callerLineNumer})) using (LogContext.PushProperty("CallingContext", new { callerMethodeName, callerFilePath, callerLineNumer}))
{ {
_MainLog.Warning(exception, messageTemplate, propertyValues); int usedPropertiesCount = _PropertiesRegex.Matches(messageTemplate).Cast<Match>().Select(m => m.Value).Distinct().Count();
if (propertyValues.Length > usedPropertiesCount)
{
using (LogContext.PushProperty("AdditionalData", propertyValues.Skip(usedPropertiesCount)))
{
_MainLog.Warning(exception, messageTemplate, propertyValues);
}
}
else
{
_MainLog.Warning(exception, messageTemplate, propertyValues);
}
} }
if(show) if(show)
ShowLogAssistant(messageTemplate, propertyValues); ShowLogAssistant(messageTemplate, propertyValues);
@@ -403,7 +502,19 @@ namespace VocaluxeLib.Log
{ {
using (LogContext.PushProperty("CallingContext", new { callerMethodeName, callerFilePath, callerLineNumer})) using (LogContext.PushProperty("CallingContext", new { callerMethodeName, callerFilePath, callerLineNumer}))
{ {
_MainLog.Error(messageTemplate, propertyValues); int usedPropertiesCount = _PropertiesRegex.Matches(messageTemplate).Cast<Match>().Select(m => m.Value).Distinct().Count();
if (propertyValues.Length > usedPropertiesCount)
{
using (LogContext.PushProperty("AdditionalData", propertyValues.Skip(usedPropertiesCount)))
{
_MainLog.Error(messageTemplate, propertyValues);
}
}
else
{
_MainLog.Error(messageTemplate, propertyValues);
}
} }
if(show) if(show)
ShowLogAssistant(messageTemplate, propertyValues); ShowLogAssistant(messageTemplate, propertyValues);
@@ -444,7 +555,19 @@ namespace VocaluxeLib.Log
{ {
using (LogContext.PushProperty("CallingContext", new { callerMethodeName, callerFilePath, callerLineNumer})) using (LogContext.PushProperty("CallingContext", new { callerMethodeName, callerFilePath, callerLineNumer}))
{ {
_MainLog.Error(exception, messageTemplate, propertyValues); int usedPropertiesCount = _PropertiesRegex.Matches(messageTemplate).Cast<Match>().Select(m => m.Value).Distinct().Count();
if (propertyValues.Length > usedPropertiesCount)
{
using (LogContext.PushProperty("AdditionalData", propertyValues.Skip(usedPropertiesCount)))
{
_MainLog.Error(exception, messageTemplate, propertyValues);
}
}
else
{
_MainLog.Error(exception, messageTemplate, propertyValues);
}
} }
if(show) if(show)
ShowLogAssistant(messageTemplate, propertyValues); ShowLogAssistant(messageTemplate, propertyValues);
@@ -491,7 +614,19 @@ namespace VocaluxeLib.Log
{ {
using (LogContext.PushProperty("CallingContext", new { callerMethodeName, callerFilePath, callerLineNumer})) using (LogContext.PushProperty("CallingContext", new { callerMethodeName, callerFilePath, callerLineNumer}))
{ {
_MainLog.Fatal(messageTemplate, propertyValues); int usedPropertiesCount = _PropertiesRegex.Matches(messageTemplate).Cast<Match>().Select(m => m.Value).Distinct().Count();
if (propertyValues.Length > usedPropertiesCount)
{
using (LogContext.PushProperty("AdditionalData", propertyValues.Skip(usedPropertiesCount)))
{
_MainLog.Fatal(messageTemplate, propertyValues);
}
}
else
{
_MainLog.Fatal(messageTemplate, propertyValues);
}
} }
if(show) if(show)
ShowLogAssistant(messageTemplate, propertyValues, true, false); ShowLogAssistant(messageTemplate, propertyValues, true, false);
@@ -540,7 +675,19 @@ namespace VocaluxeLib.Log
{ {
using (LogContext.PushProperty("CallingContext", new { callerMethodeName, callerFilePath, callerLineNumer})) using (LogContext.PushProperty("CallingContext", new { callerMethodeName, callerFilePath, callerLineNumer}))
{ {
_MainLog.Fatal(exception, messageTemplate, propertyValues); int usedPropertiesCount = _PropertiesRegex.Matches(messageTemplate).Cast<Match>().Select(m => m.Value).Distinct().Count();
if (propertyValues.Length > usedPropertiesCount)
{
using (LogContext.PushProperty("AdditionalData", propertyValues.Skip(usedPropertiesCount)))
{
_MainLog.Fatal(exception, messageTemplate, propertyValues);
}
}
else
{
_MainLog.Fatal(exception, messageTemplate, propertyValues);
}
} }
if(show) if(show)
ShowLogAssistant(messageTemplate, propertyValues, true, false); ShowLogAssistant(messageTemplate, propertyValues, true, false);
@@ -587,7 +734,19 @@ namespace VocaluxeLib.Log
{ {
using (LogContext.PushProperty("CallingContext", new { callerMethodeName, callerFilePath, callerLineNumer})) using (LogContext.PushProperty("CallingContext", new { callerMethodeName, callerFilePath, callerLineNumer}))
{ {
_SongLog.Verbose(messageTemplate, propertyValues); int usedPropertiesCount = _PropertiesRegex.Matches(messageTemplate).Cast<Match>().Select(m => m.Value).Distinct().Count();
if (propertyValues.Length > usedPropertiesCount)
{
using (LogContext.PushProperty("AdditionalData", propertyValues.Skip(usedPropertiesCount)))
{
_SongLog.Verbose(messageTemplate, propertyValues);
}
}
else
{
_SongLog.Verbose(messageTemplate, propertyValues);
}
} }
} }
@@ -622,7 +781,19 @@ namespace VocaluxeLib.Log
{ {
using (LogContext.PushProperty("CallingContext", new { callerMethodeName, callerFilePath, callerLineNumer})) using (LogContext.PushProperty("CallingContext", new { callerMethodeName, callerFilePath, callerLineNumer}))
{ {
_SongLog.Verbose(exception, messageTemplate, propertyValues); int usedPropertiesCount = _PropertiesRegex.Matches(messageTemplate).Cast<Match>().Select(m => m.Value).Distinct().Count();
if (propertyValues.Length > usedPropertiesCount)
{
using (LogContext.PushProperty("AdditionalData", propertyValues.Skip(usedPropertiesCount)))
{
_SongLog.Verbose(exception, messageTemplate, propertyValues);
}
}
else
{
_SongLog.Verbose(exception, messageTemplate, propertyValues);
}
} }
} }
@@ -659,7 +830,19 @@ namespace VocaluxeLib.Log
{ {
using (LogContext.PushProperty("CallingContext", new { callerMethodeName, callerFilePath, callerLineNumer})) using (LogContext.PushProperty("CallingContext", new { callerMethodeName, callerFilePath, callerLineNumer}))
{ {
_SongLog.Debug(messageTemplate, propertyValues); int usedPropertiesCount = _PropertiesRegex.Matches(messageTemplate).Cast<Match>().Select(m => m.Value).Distinct().Count();
if (propertyValues.Length > usedPropertiesCount)
{
using (LogContext.PushProperty("AdditionalData", propertyValues.Skip(usedPropertiesCount)))
{
_SongLog.Debug(messageTemplate, propertyValues);
}
}
else
{
_SongLog.Debug(messageTemplate, propertyValues);
}
} }
} }
@@ -694,7 +877,19 @@ namespace VocaluxeLib.Log
{ {
using (LogContext.PushProperty("CallingContext", new { callerMethodeName, callerFilePath, callerLineNumer})) using (LogContext.PushProperty("CallingContext", new { callerMethodeName, callerFilePath, callerLineNumer}))
{ {
_SongLog.Debug(exception, messageTemplate, propertyValues); int usedPropertiesCount = _PropertiesRegex.Matches(messageTemplate).Cast<Match>().Select(m => m.Value).Distinct().Count();
if (propertyValues.Length > usedPropertiesCount)
{
using (LogContext.PushProperty("AdditionalData", propertyValues.Skip(usedPropertiesCount)))
{
_SongLog.Debug(exception, messageTemplate, propertyValues);
}
}
else
{
_SongLog.Debug(exception, messageTemplate, propertyValues);
}
} }
} }
@@ -731,7 +926,19 @@ namespace VocaluxeLib.Log
{ {
using (LogContext.PushProperty("CallingContext", new { callerMethodeName, callerFilePath, callerLineNumer})) using (LogContext.PushProperty("CallingContext", new { callerMethodeName, callerFilePath, callerLineNumer}))
{ {
_SongLog.Information(messageTemplate, propertyValues); int usedPropertiesCount = _PropertiesRegex.Matches(messageTemplate).Cast<Match>().Select(m => m.Value).Distinct().Count();
if (propertyValues.Length > usedPropertiesCount)
{
using (LogContext.PushProperty("AdditionalData", propertyValues.Skip(usedPropertiesCount)))
{
_SongLog.Information(messageTemplate, propertyValues);
}
}
else
{
_SongLog.Information(messageTemplate, propertyValues);
}
} }
} }
@@ -766,7 +973,19 @@ namespace VocaluxeLib.Log
{ {
using (LogContext.PushProperty("CallingContext", new { callerMethodeName, callerFilePath, callerLineNumer})) using (LogContext.PushProperty("CallingContext", new { callerMethodeName, callerFilePath, callerLineNumer}))
{ {
_SongLog.Information(exception, messageTemplate, propertyValues); int usedPropertiesCount = _PropertiesRegex.Matches(messageTemplate).Cast<Match>().Select(m => m.Value).Distinct().Count();
if (propertyValues.Length > usedPropertiesCount)
{
using (LogContext.PushProperty("AdditionalData", propertyValues.Skip(usedPropertiesCount)))
{
_SongLog.Information(exception, messageTemplate, propertyValues);
}
}
else
{
_SongLog.Information(exception, messageTemplate, propertyValues);
}
} }
} }
@@ -803,7 +1022,19 @@ namespace VocaluxeLib.Log
{ {
using (LogContext.PushProperty("CallingContext", new { callerMethodeName, callerFilePath, callerLineNumer})) using (LogContext.PushProperty("CallingContext", new { callerMethodeName, callerFilePath, callerLineNumer}))
{ {
_SongLog.Warning(messageTemplate, propertyValues); int usedPropertiesCount = _PropertiesRegex.Matches(messageTemplate).Cast<Match>().Select(m => m.Value).Distinct().Count();
if (propertyValues.Length > usedPropertiesCount)
{
using (LogContext.PushProperty("AdditionalData", propertyValues.Skip(usedPropertiesCount)))
{
_SongLog.Warning(messageTemplate, propertyValues);
}
}
else
{
_SongLog.Warning(messageTemplate, propertyValues);
}
} }
} }
@@ -838,7 +1069,19 @@ namespace VocaluxeLib.Log
{ {
using (LogContext.PushProperty("CallingContext", new { callerMethodeName, callerFilePath, callerLineNumer})) using (LogContext.PushProperty("CallingContext", new { callerMethodeName, callerFilePath, callerLineNumer}))
{ {
_SongLog.Warning(exception, messageTemplate, propertyValues); int usedPropertiesCount = _PropertiesRegex.Matches(messageTemplate).Cast<Match>().Select(m => m.Value).Distinct().Count();
if (propertyValues.Length > usedPropertiesCount)
{
using (LogContext.PushProperty("AdditionalData", propertyValues.Skip(usedPropertiesCount)))
{
_SongLog.Warning(exception, messageTemplate, propertyValues);
}
}
else
{
_SongLog.Warning(exception, messageTemplate, propertyValues);
}
} }
} }
@@ -875,7 +1118,19 @@ namespace VocaluxeLib.Log
{ {
using (LogContext.PushProperty("CallingContext", new { callerMethodeName, callerFilePath, callerLineNumer})) using (LogContext.PushProperty("CallingContext", new { callerMethodeName, callerFilePath, callerLineNumer}))
{ {
_SongLog.Error(messageTemplate, propertyValues); int usedPropertiesCount = _PropertiesRegex.Matches(messageTemplate).Cast<Match>().Select(m => m.Value).Distinct().Count();
if (propertyValues.Length > usedPropertiesCount)
{
using (LogContext.PushProperty("AdditionalData", propertyValues.Skip(usedPropertiesCount)))
{
_SongLog.Error(messageTemplate, propertyValues);
}
}
else
{
_SongLog.Error(messageTemplate, propertyValues);
}
} }
} }
@@ -910,7 +1165,19 @@ namespace VocaluxeLib.Log
{ {
using (LogContext.PushProperty("CallingContext", new { callerMethodeName, callerFilePath, callerLineNumer})) using (LogContext.PushProperty("CallingContext", new { callerMethodeName, callerFilePath, callerLineNumer}))
{ {
_SongLog.Error(exception, messageTemplate, propertyValues); int usedPropertiesCount = _PropertiesRegex.Matches(messageTemplate).Cast<Match>().Select(m => m.Value).Distinct().Count();
if (propertyValues.Length > usedPropertiesCount)
{
using (LogContext.PushProperty("AdditionalData", propertyValues.Skip(usedPropertiesCount)))
{
_SongLog.Error(exception, messageTemplate, propertyValues);
}
}
else
{
_SongLog.Error(exception, messageTemplate, propertyValues);
}
} }
} }
+29 -2
View File
@@ -39,7 +39,9 @@
using System; using System;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Text.RegularExpressions;
using Serilog.Context; using Serilog.Context;
using Serilog.Core; using Serilog.Core;
@@ -47,6 +49,7 @@ namespace VocaluxeLib.Log
{ {
public static partial class CLog public static partial class CLog
{ {
private static Regex _PropertiesRegex = new Regex("{[^}]+}");
public static object[] Params(params object[] propertyValues) public static object[] Params(params object[] propertyValues)
{ {
@@ -111,7 +114,19 @@ namespace VocaluxeLib.Log
{ {
using (LogContext.PushProperty("CallingContext", new { callerMethodeName, callerFilePath, callerLineNumer})) using (LogContext.PushProperty("CallingContext", new { callerMethodeName, callerFilePath, callerLineNumer}))
{ {
<#= Log == "Main"?"_MainLog":"_SongLog" #>.<#= LogLevel #>(messageTemplate, propertyValues); int usedPropertiesCount = _PropertiesRegex.Matches(messageTemplate).Cast<Match>().Select(m => m.Value).Distinct().Count();
if (propertyValues.Length > usedPropertiesCount)
{
using (LogContext.PushProperty("AdditionalData", propertyValues.Skip(usedPropertiesCount)))
{
<#= Log == "Main"?"_MainLog":"_SongLog" #>.<#= LogLevel #>(messageTemplate, propertyValues);
}
}
else
{
<#= Log == "Main"?"_MainLog":"_SongLog" #>.<#= LogLevel #>(messageTemplate, propertyValues);
}
} }
<# if(Log == "Main") { #> <# if(Log == "Main") { #>
if(show) if(show)
@@ -172,7 +187,19 @@ namespace VocaluxeLib.Log
{ {
using (LogContext.PushProperty("CallingContext", new { callerMethodeName, callerFilePath, callerLineNumer})) using (LogContext.PushProperty("CallingContext", new { callerMethodeName, callerFilePath, callerLineNumer}))
{ {
<#= Log == "Main"?"_MainLog":"_SongLog" #>.<#= LogLevel #>(exception, messageTemplate, propertyValues); int usedPropertiesCount = _PropertiesRegex.Matches(messageTemplate).Cast<Match>().Select(m => m.Value).Distinct().Count();
if (propertyValues.Length > usedPropertiesCount)
{
using (LogContext.PushProperty("AdditionalData", propertyValues.Skip(usedPropertiesCount)))
{
<#= Log == "Main"?"_MainLog":"_SongLog" #>.<#= LogLevel #>(exception, messageTemplate, propertyValues);
}
}
else
{
<#= Log == "Main"?"_MainLog":"_SongLog" #>.<#= LogLevel #>(exception, messageTemplate, propertyValues);
}
} }
<# if(Log == "Main") { #> <# if(Log == "Main") { #>
if(show) if(show)