-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #92 from Cysharp/hadashiA/named-param
Add helper method to name parameter like `$”{(keyName, value)}`
- Loading branch information
Showing
4 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using System; | ||
using System.Text.Json; | ||
using FluentAssertions; | ||
using Microsoft.Extensions.Logging; | ||
using ZLogger.Formatters; | ||
|
||
namespace ZLogger.Tests | ||
{ | ||
public class NamedParamTest | ||
{ | ||
[Fact] | ||
public void StructuredLoggingOptions() | ||
{ | ||
var options = new ZLoggerOptions(); | ||
options.UseJsonFormatter(); | ||
|
||
var processor = new TestProcessor(options); | ||
using var loggerFactory = LoggerFactory.Create(x => | ||
{ | ||
x.SetMinimumLevel(LogLevel.Debug); | ||
x.AddZLoggerLogProcessor(processor); | ||
}); | ||
var logger = loggerFactory.CreateLogger("test"); | ||
|
||
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; | ||
|
||
doc.GetProperty("Message").GetString().Should().Be("100 00200 2023-12-31"); | ||
doc.GetProperty("TAKO").GetInt32().Should().Be(100); | ||
doc.GetProperty("YAKI").GetInt32().Should().Be(200); | ||
doc.GetProperty("T").GetDateTime().Should().Be(new DateTime(2023, 12, 31)); | ||
} | ||
} | ||
} |