Skip to content
Open
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
16 changes: 13 additions & 3 deletions src/Marten/DefaultMartenLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public void LogSuccess(NpgsqlCommand command)
{
if (Inner.IsEnabled(LogLevel.Debug))
{
var duration = _timestamp.HasValue ? Stopwatch.GetElapsedTime(_timestamp!.Value) : 0.Seconds();
var duration = GetDuration();
var parameters = command.Parameters
.Select(p => $" {p.ParameterName}: {p.Value}")
.Join(Environment.NewLine);
Expand All @@ -47,7 +47,7 @@ public void LogSuccess(NpgsqlBatch batch)
{
if (Inner.IsEnabled(LogLevel.Debug))
{
var duration = Stopwatch.GetElapsedTime(_timestamp!.Value);
var duration = GetDuration();
foreach (var command in batch.BatchCommands)
{
var parameters = command.Parameters.OfType<NpgsqlParameter>()
Expand Down Expand Up @@ -88,7 +88,7 @@ public void RecordSavedChanges(IDocumentSession session, IChangeSet commit)
{
if (Inner.IsEnabled(LogLevel.Debug))
{
var duration = _timestamp.HasValue ? Stopwatch.GetElapsedTime(_timestamp!.Value) : 0.Seconds();
var duration = GetDuration();
_loggerOutput.RecordSavedChanges(commit.Updated.Count(),
duration.TotalMilliseconds,
commit.Inserted.Count(),
Expand All @@ -111,6 +111,16 @@ public void OnBeforeExecute(NpgsqlBatch batch)
_timestamp = Stopwatch.GetTimestamp();
}
}

private TimeSpan GetDuration()
{
if (_timestamp.HasValue)
{
return Stopwatch.GetElapsedTime(_timestamp.Value);
}

return 0.Seconds();
}
}

internal sealed partial class DefaultLoggingWriter
Expand Down
Loading