diff --git a/src/ZLogger.MessagePack/MessagePackZLoggerFormatter.cs b/src/ZLogger.MessagePack/MessagePackZLoggerFormatter.cs index 1edaffea..faf11447 100644 --- a/src/ZLogger.MessagePack/MessagePackZLoggerFormatter.cs +++ b/src/ZLogger.MessagePack/MessagePackZLoggerFormatter.cs @@ -1,5 +1,4 @@ using System; -using System.Linq; using System.Buffers; using MessagePack; using Microsoft.Extensions.Logging; diff --git a/src/ZLogger/LogStates/InterpolatedStringLogState.cs b/src/ZLogger/LogStates/InterpolatedStringLogState.cs index 6453e9eb..67f9a6f6 100644 --- a/src/ZLogger/LogStates/InterpolatedStringLogState.cs +++ b/src/ZLogger/LogStates/InterpolatedStringLogState.cs @@ -26,6 +26,7 @@ public InterpolatedStringLogState(MessageSequence messageSequence, MagicalBox ma this.parameters = ArrayPool.Shared.Rent(parameters.Length); parameters.CopyTo(this.parameters); + ParameterCount = parameters.Length; this.messageSequence = messageSequence; this.magicalBox = new MagicalBox(magicalBoxStorage, magicalBox.Written); @@ -34,7 +35,7 @@ public InterpolatedStringLogState(MessageSequence messageSequence, MagicalBox ma public IZLoggerEntry CreateEntry(LogInfo info) { // state needs clone. - var newState = new InterpolatedStringLogState(messageSequence, this.magicalBox, this.parameters); + var newState = new InterpolatedStringLogState(messageSequence, this.magicalBox, this.parameters.AsSpan(0, ParameterCount)); // Create Entry with cloned state(state will dispose when entry was disposed) return ZLoggerEntry.Create(info, newState); @@ -112,10 +113,7 @@ public string GetParameterKeyAsString(int index) { return value; } - else - { - return (T?)p.BoxedValue; - } + return (T?)p.BoxedValue; } public Type GetParameterType(int index) diff --git a/src/ZLogger/ZLoggerInterpolatedStringHandler.LogLevel.cs b/src/ZLogger/ZLoggerInterpolatedStringHandler.LogLevel.cs index 8f89c125..ef6b91a0 100644 --- a/src/ZLogger/ZLoggerInterpolatedStringHandler.LogLevel.cs +++ b/src/ZLogger/ZLoggerInterpolatedStringHandler.LogLevel.cs @@ -22,6 +22,12 @@ public void AppendFormatted(T value, int alignment = 0, string? format = null { this.innerHandler.AppendFormatted(value, alignment, format, argumentName); } + + public void AppendFormatted(Nullable value, int alignment = 0, string? format = null, [CallerArgumentExpression("value")] string? argumentName = null) + where T : struct + { + this.innerHandler.AppendFormatted(value, alignment, format, argumentName); + } } [InterpolatedStringHandler] @@ -42,6 +48,12 @@ public void AppendFormatted(T value, int alignment = 0, string? format = null { this.innerHandler.AppendFormatted(value, alignment, format, argumentName); } + + public void AppendFormatted(Nullable value, int alignment = 0, string? format = null, [CallerArgumentExpression("value")] string? argumentName = null) + where T : struct + { + this.innerHandler.AppendFormatted(value, alignment, format, argumentName); + } } [InterpolatedStringHandler] @@ -62,6 +74,12 @@ public void AppendFormatted(T value, int alignment = 0, string? format = null { this.innerHandler.AppendFormatted(value, alignment, format, argumentName); } + + public void AppendFormatted(Nullable value, int alignment = 0, string? format = null, [CallerArgumentExpression("value")] string? argumentName = null) + where T : struct + { + this.innerHandler.AppendFormatted(value, alignment, format, argumentName); + } } [InterpolatedStringHandler] @@ -82,6 +100,12 @@ public void AppendFormatted(T value, int alignment = 0, string? format = null { this.innerHandler.AppendFormatted(value, alignment, format, argumentName); } + + public void AppendFormatted(Nullable value, int alignment = 0, string? format = null, [CallerArgumentExpression("value")] string? argumentName = null) + where T : struct + { + this.innerHandler.AppendFormatted(value, alignment, format, argumentName); + } } [InterpolatedStringHandler] @@ -102,6 +126,12 @@ public void AppendFormatted(T value, int alignment = 0, string? format = null { this.innerHandler.AppendFormatted(value, alignment, format, argumentName); } + + public void AppendFormatted(Nullable value, int alignment = 0, string? format = null, [CallerArgumentExpression("value")] string? argumentName = null) + where T : struct + { + this.innerHandler.AppendFormatted(value, alignment, format, argumentName); + } } [InterpolatedStringHandler] @@ -122,5 +152,11 @@ public void AppendFormatted(T value, int alignment = 0, string? format = null { this.innerHandler.AppendFormatted(value, alignment, format, argumentName); } + + public void AppendFormatted(Nullable value, int alignment = 0, string? format = null, [CallerArgumentExpression("value")] string? argumentName = null) + where T : struct + { + this.innerHandler.AppendFormatted(value, alignment, format, argumentName); + } } diff --git a/src/ZLogger/ZLoggerInterpolatedStringHandler.LogLevel.tt b/src/ZLogger/ZLoggerInterpolatedStringHandler.LogLevel.tt index ebbd3cfa..10d51b9a 100644 --- a/src/ZLogger/ZLoggerInterpolatedStringHandler.LogLevel.tt +++ b/src/ZLogger/ZLoggerInterpolatedStringHandler.LogLevel.tt @@ -32,6 +32,12 @@ public ref struct ZLogger<#= logLevel #>InterpolatedStringHandler { this.innerHandler.AppendFormatted(value, alignment, format, argumentName); } + + public void AppendFormatted(Nullable value, int alignment = 0, string? format = null, [CallerArgumentExpression("value")] string? argumentName = null) + where T : struct + { + this.innerHandler.AppendFormatted(value, alignment, format, argumentName); + } } <# } #> \ No newline at end of file