Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions Serilog.Enrichers.CallStack.Tests/CallStackEnricherTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,67 @@ public void Enrich_WithMethodParametersInExceptionFormat_IncludesParameters()
callStack.Should().Contain(")");
}

[Fact]
public void Enrich_WithFilePaths_NormalizesPathSeparators()
{
// Arrange
var config = new CallStackEnricherConfiguration()
.WithCallStackFormat(useExceptionLikeFormat: false)
.WithIncludes(fileName: true);

using var logger = new LoggerConfiguration()
.Enrich.WithCallStack(config)
.WriteTo.InMemory()
.CreateLogger();

// Act
LogFromMethod(logger);

// Assert
var logEvent = GetLatestLogEvent();
if (logEvent.Properties.ContainsKey("FileName"))
{
var fileName = logEvent.Properties["FileName"].ToString().Trim('"');

// On all platforms, should use forward slashes or just filename
// This normalizes cross-platform behavior
if (fileName.Contains("\\"))
{
// If we have backslashes, normalize them
fileName.Should().MatchRegex(@".*[/\\]CallStackEnricherTests\.cs");
}
else
{
// Should at least contain the filename
fileName.Should().Contain("CallStackEnricherTests.cs");
}
}
}

[Fact]
public void Enrich_WithLineNumbers_IncludesValidLineNumbers()
{
// Arrange
var config = new CallStackEnricherConfiguration()
.WithCallStackFormat(useExceptionLikeFormat: true)
.WithIncludes(lineNumber: true);

using var logger = new LoggerConfiguration()
.Enrich.WithCallStack(config)
.WriteTo.InMemory()
.CreateLogger();

// Act
LogFromMethod(logger); // This call is at a specific line

// Assert
var logEvent = GetLatestLogEvent();
var callStack = logEvent.Properties["CallStack"].ToString();

// Should contain line number format (method:line)
callStack.Should().MatchRegex(@".*:\d+.*");
}

private static void CallMultipleMethodsDeep(ILogger logger)
{
CallMethodThatLogs(logger);
Expand Down
Loading
Loading