Skip to content
Merged
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
9 changes: 7 additions & 2 deletions src/Middleware/HttpLogging/src/FileLoggerProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ internal partial class FileLoggerProcessor : IAsyncDisposable
private bool _maxFilesReached;
private TimeSpan _flushInterval;
private W3CLoggingFields _fields;
private DateTime _today = DateTime.Now;
private DateTime _today;
private bool _firstFile = true;

private readonly IOptionsMonitor<W3CLoggerOptions> _options;
Expand All @@ -40,6 +40,9 @@ internal partial class FileLoggerProcessor : IAsyncDisposable
private readonly Task _outputTask;
private readonly CancellationTokenSource _cancellationTokenSource;

// Internal to allow for testing
internal ISystemDateTime SystemDateTime {get; set;} = new SystemDateTime();

private readonly object _pathLock = new object();

public FileLoggerProcessor(IOptionsMonitor<W3CLoggerOptions> options, IHostEnvironment environment, ILoggerFactory factory)
Expand Down Expand Up @@ -98,6 +101,8 @@ public FileLoggerProcessor(IOptionsMonitor<W3CLoggerOptions> options, IHostEnvir
}
});

_today = SystemDateTime.Now;

// Start message queue processor
_cancellationTokenSource = new CancellationTokenSource();
_outputTask = Task.Run(ProcessLogQueue);
Expand Down Expand Up @@ -155,7 +160,7 @@ private async Task ProcessLogQueue()
private async Task WriteMessagesAsync(List<string> messages, CancellationToken cancellationToken)
{
// Files are written up to _maxFileSize before rolling to a new file
DateTime today = DateTime.Now;
DateTime today = SystemDateTime.Now;

if (!TryCreateDirectory())
{
Expand Down
13 changes: 13 additions & 0 deletions src/Middleware/HttpLogging/src/ISystemDateTime.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

namespace Microsoft.AspNetCore.HttpLogging
{
internal interface ISystemDateTime
{
/// <summary>
/// Retrieves the date and time currently set for this machine.
/// </summary>
DateTime Now { get; }
}
}
10 changes: 10 additions & 0 deletions src/Middleware/HttpLogging/src/SystemDateTime.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

namespace Microsoft.AspNetCore.HttpLogging
{
internal class SystemDateTime : ISystemDateTime
{
public DateTime Now => DateTime.Now;
}
}
Loading