diff options
| author | Cody Robibero <cody@robibe.ro> | 2021-10-26 18:42:17 -0600 |
|---|---|---|
| committer | Cody Robibero <cody@robibe.ro> | 2021-10-26 18:42:17 -0600 |
| commit | a6357f89abb40deaa84ed0ea52010c098e769e62 (patch) | |
| tree | e2697de1b14d3901a0e3d6263c2533f244345c09 /MediaBrowser.Controller/ClientEvent/ClientEventLogger.cs | |
| parent | f78f1e834ce1907157d4d43cf8564cf40d05fb9f (diff) | |
Add ability to upload entire file
Diffstat (limited to 'MediaBrowser.Controller/ClientEvent/ClientEventLogger.cs')
| -rw-r--r-- | MediaBrowser.Controller/ClientEvent/ClientEventLogger.cs | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/MediaBrowser.Controller/ClientEvent/ClientEventLogger.cs b/MediaBrowser.Controller/ClientEvent/ClientEventLogger.cs index c00a38d1b..bdc1a7eff 100644 --- a/MediaBrowser.Controller/ClientEvent/ClientEventLogger.cs +++ b/MediaBrowser.Controller/ClientEvent/ClientEventLogger.cs @@ -1,4 +1,6 @@ using System; +using System.IO; +using System.Threading.Tasks; using MediaBrowser.Model.ClientLog; using Microsoft.Extensions.Logging; @@ -9,14 +11,19 @@ namespace MediaBrowser.Controller.ClientEvent { private const string LogString = "[{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz}] [{Level}] [{ClientName}:{ClientVersion}]: UserId: {UserId} DeviceId: {DeviceId}{NewLine}{Message}"; private readonly ILogger<ClientEventLogger> _logger; + private readonly IServerApplicationPaths _applicationPaths; /// <summary> /// Initializes a new instance of the <see cref="ClientEventLogger"/> class. /// </summary> /// <param name="logger">Instance of the <see cref="ILogger{ClientEventLogger}"/> interface.</param> - public ClientEventLogger(ILogger<ClientEventLogger> logger) + /// <param name="applicationPaths">Instance of the <see cref="IServerApplicationPaths"/> interface.</param> + public ClientEventLogger( + ILogger<ClientEventLogger> logger, + IServerApplicationPaths applicationPaths) { _logger = logger; + _applicationPaths = applicationPaths; } /// <inheritdoc /> @@ -34,5 +41,16 @@ namespace MediaBrowser.Controller.ClientEvent Environment.NewLine, clientLogEvent.Message); } + + /// <inheritdoc /> + public async Task WriteFileAsync(string fileName, Stream fileContents) + { + // Force naming convention: upload_YYYYMMDD_$name + fileName = $"upload_{DateTime.UtcNow:yyyyMMdd}_{fileName}"; + var logFilePath = Path.Combine(_applicationPaths.LogDirectoryPath, fileName); + await using var fileStream = new FileStream(logFilePath, FileMode.CreateNew, FileAccess.Write, FileShare.None); + await fileContents.CopyToAsync(fileStream).ConfigureAwait(false); + await fileStream.FlushAsync().ConfigureAwait(false); + } } -}
\ No newline at end of file +} |
