Skip to content

Commit 6c52f28

Browse files
authored
Merge pull request #275 from serilog/dev
9.0.2 Release
2 parents 2861b67 + 49e90a7 commit 6c52f28

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

Directory.Version.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project>
22
<PropertyGroup>
33
<!-- This must match the major and minor components of the referenced Microsoft.Extensions.Logging package. -->
4-
<VersionPrefix>9.0.1</VersionPrefix>
4+
<VersionPrefix>9.0.2</VersionPrefix>
55
</PropertyGroup>
66
</Project>

src/Serilog.Extensions.Logging/Extensions/Logging/SerilogLogger.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public SerilogLogger(
4040
_provider = provider ?? throw new ArgumentNullException(nameof(provider));
4141

4242
// If a logger was passed, the provider has already added itself as an enricher
43-
_logger = logger ?? Serilog.Log.Logger.ForContext(new[] { provider });
43+
_logger = logger ?? Serilog.Log.Logger.ForContext([provider]);
4444

4545
if (name != null)
4646
{
@@ -91,7 +91,7 @@ LogEvent PrepareWrite<TState>(LogEventLevel level, EventId eventId, TState state
9191

9292
var properties = new Dictionary<string, LogEventPropertyValue>();
9393

94-
if (state is IEnumerable<KeyValuePair<string, object>> structure)
94+
if (state is IEnumerable<KeyValuePair<string, object?>> structure)
9595
{
9696
foreach (var property in structure)
9797
{
@@ -155,7 +155,7 @@ LogEvent PrepareWrite<TState>(LogEventLevel level, EventId eventId, TState state
155155

156156
// The overridden `!=` operator on this type ignores `Name`.
157157
if (eventId.Id != 0 || eventId.Name != null)
158-
properties.Add("EventId", _eventIdPropertyCache.GetOrCreatePropertyValue(in eventId));
158+
properties["EventId"] = _eventIdPropertyCache.GetOrCreatePropertyValue(in eventId);
159159

160160
var (traceId, spanId) = Activity.Current is { } activity ?
161161
(activity.TraceId, activity.SpanId) :

test/Serilog.Extensions.Logging.Tests/SerilogLoggerTests.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -618,4 +618,20 @@ static void AssertHasScalarProperty(LogEvent logEvent, string name, object? expe
618618
var scalar = Assert.IsType<ScalarValue>(result);
619619
Assert.Equal(expectedValue, scalar.Value);
620620
}
621+
622+
[Fact]
623+
public void ConflictingEventIdTemplatePropertyIsIgnored()
624+
{
625+
var (logger, sink) = SetUp(LogLevel.Trace);
626+
627+
var loggedEventId = 17;
628+
logger.LogInformation(loggedEventId, "{EventId}", 42);
629+
630+
var write = Assert.Single(sink.Writes);
631+
var recordedEventIdProperty = Assert.IsType<StructureValue>(write.Properties["EventId"]);
632+
var recordedEventIdStructure = Assert.Single(recordedEventIdProperty.Properties, p => p.Name == "Id");
633+
var recordedEventIdPropertyValue = Assert.IsType<ScalarValue>(recordedEventIdStructure.Value);
634+
var recordedEventId = Assert.IsType<int>(recordedEventIdPropertyValue.Value);
635+
Assert.Equal(loggedEventId, recordedEventId);
636+
}
621637
}

0 commit comments

Comments
 (0)