Skip to content

Commit

Permalink
Use (string, T) instead of ZLogger.Param
Browse files Browse the repository at this point in the history
  • Loading branch information
hadashiA committed Oct 20, 2023
1 parent a77f06b commit b8de8d1
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 37 deletions.
24 changes: 12 additions & 12 deletions src/ZLogger/ZLoggerInterpolatedStringHandler.LogLevel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ public void AppendFormatted<T>(Nullable<T> value, int alignment = 0, string? for
this.innerHandler.AppendFormatted<T>(value, alignment, format, argumentName);
}

public void AppendFormatted<T>(ZLoggerNamedParam<T> value, int alignment = 0, string? format = null, string? _ = null)
public void AppendFormatted<T>((string, T) namedValue, int alignment = 0, string? format = null, string? _ = null)
{
this.innerHandler.AppendFormatted(value, alignment, format);
this.innerHandler.AppendFormatted(namedValue, alignment, format);
}
}

Expand Down Expand Up @@ -60,9 +60,9 @@ public void AppendFormatted<T>(Nullable<T> value, int alignment = 0, string? for
this.innerHandler.AppendFormatted<T>(value, alignment, format, argumentName);
}

public void AppendFormatted<T>(ZLoggerNamedParam<T> value, int alignment = 0, string? format = null, string? _ = null)
public void AppendFormatted<T>((string, T) namedValue, int alignment = 0, string? format = null, string? _ = null)
{
this.innerHandler.AppendFormatted(value, alignment, format);
this.innerHandler.AppendFormatted(namedValue, alignment, format);
}
}

Expand Down Expand Up @@ -91,9 +91,9 @@ public void AppendFormatted<T>(Nullable<T> value, int alignment = 0, string? for
this.innerHandler.AppendFormatted<T>(value, alignment, format, argumentName);
}

public void AppendFormatted<T>(ZLoggerNamedParam<T> value, int alignment = 0, string? format = null, string? _ = null)
public void AppendFormatted<T>((string, T) namedValue, int alignment = 0, string? format = null, string? _ = null)
{
this.innerHandler.AppendFormatted(value, alignment, format);
this.innerHandler.AppendFormatted(namedValue, alignment, format);
}
}

Expand Down Expand Up @@ -122,9 +122,9 @@ public void AppendFormatted<T>(Nullable<T> value, int alignment = 0, string? for
this.innerHandler.AppendFormatted<T>(value, alignment, format, argumentName);
}

public void AppendFormatted<T>(ZLoggerNamedParam<T> value, int alignment = 0, string? format = null, string? _ = null)
public void AppendFormatted<T>((string, T) namedValue, int alignment = 0, string? format = null, string? _ = null)
{
this.innerHandler.AppendFormatted(value, alignment, format);
this.innerHandler.AppendFormatted(namedValue, alignment, format);
}
}

Expand Down Expand Up @@ -153,9 +153,9 @@ public void AppendFormatted<T>(Nullable<T> value, int alignment = 0, string? for
this.innerHandler.AppendFormatted<T>(value, alignment, format, argumentName);
}

public void AppendFormatted<T>(ZLoggerNamedParam<T> value, int alignment = 0, string? format = null, string? _ = null)
public void AppendFormatted<T>((string, T) namedValue, int alignment = 0, string? format = null, string? _ = null)
{
this.innerHandler.AppendFormatted(value, alignment, format);
this.innerHandler.AppendFormatted(namedValue, alignment, format);
}
}

Expand Down Expand Up @@ -184,9 +184,9 @@ public void AppendFormatted<T>(Nullable<T> value, int alignment = 0, string? for
this.innerHandler.AppendFormatted<T>(value, alignment, format, argumentName);
}

public void AppendFormatted<T>(ZLoggerNamedParam<T> value, int alignment = 0, string? format = null, string? _ = null)
public void AppendFormatted<T>((string, T) namedValue, int alignment = 0, string? format = null, string? _ = null)
{
this.innerHandler.AppendFormatted(value, alignment, format);
this.innerHandler.AppendFormatted(namedValue, alignment, format);
}
}

4 changes: 2 additions & 2 deletions src/ZLogger/ZLoggerInterpolatedStringHandler.LogLevel.tt
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ public ref struct ZLogger<#= logLevel #>InterpolatedStringHandler
this.innerHandler.AppendFormatted<T>(value, alignment, format, argumentName);
}

public void AppendFormatted<T>(ZLoggerNamedParam<T> value, int alignment = 0, string? format = null, string? _ = null)
public void AppendFormatted<T>((string, T) namedValue, int alignment = 0, string? format = null, string? _ = null)
{
this.innerHandler.AppendFormatted(value, alignment, format);
this.innerHandler.AppendFormatted(namedValue, alignment, format);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/ZLogger/ZLoggerInterpolatedStringHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ public void AppendFormatted<T>(Nullable<T> value, int alignment = 0, string? for
}
}

public void AppendFormatted<T>(ZLoggerNamedParam<T> value, int alignment = 0, string? format = null, string? _ = null)
public void AppendFormatted<T>((string, T) namedValue, int alignment = 0, string? format = null, string? _ = null)
{
AppendFormatted(value.Value, alignment, format, value.Name);
AppendFormatted(namedValue.Item2, alignment, format, namedValue.Item1);
}

internal InterpolatedStringLogState GetStateAndClear()
Expand Down
20 changes: 0 additions & 20 deletions src/ZLogger/ZLoggerParam.cs

This file was deleted.

2 changes: 1 addition & 1 deletion tests/ZLogger.Tests/NamedParamTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public void StructuredLoggingOptions()
});
var logger = loggerFactory.CreateLogger("test");

logger.ZLogInformation($"{ZLogger.Param("TAKO", 100)} {ZLogger.Param("YAKI", 200):D5} {ZLogger.Param("T", new DateTime(2023, 12, 31)),15:yyyy-MM-dd}");
logger.ZLogInformation($"{("TAKO", 100)} {("YAKI", 200):D5} {("T", new DateTime(2023, 12, 31)),15:yyyy-MM-dd}");

var json = processor.EntryMessages.Dequeue();
var doc = JsonDocument.Parse(json).RootElement;
Expand Down

0 comments on commit b8de8d1

Please sign in to comment.