| | 1 | | using System; |
| | 2 | | using System.IO; |
| | 3 | | using System.Threading.Tasks; |
| | 4 | |
|
| | 5 | | namespace MediaBrowser.Controller.ClientEvent |
| | 6 | | { |
| | 7 | | /// <inheritdoc /> |
| | 8 | | public class ClientEventLogger : IClientEventLogger |
| | 9 | | { |
| | 10 | | private readonly IServerApplicationPaths _applicationPaths; |
| | 11 | |
|
| | 12 | | /// <summary> |
| | 13 | | /// Initializes a new instance of the <see cref="ClientEventLogger"/> class. |
| | 14 | | /// </summary> |
| | 15 | | /// <param name="applicationPaths">Instance of the <see cref="IServerApplicationPaths"/> interface.</param> |
| | 16 | | public ClientEventLogger(IServerApplicationPaths applicationPaths) |
| | 17 | | { |
| 0 | 18 | | _applicationPaths = applicationPaths; |
| 0 | 19 | | } |
| | 20 | |
|
| | 21 | | /// <inheritdoc /> |
| | 22 | | public async Task<string> WriteDocumentAsync(string clientName, string clientVersion, Stream fileContents) |
| | 23 | | { |
| | 24 | | var fileName = $"upload_{clientName}_{clientVersion}_{DateTime.UtcNow:yyyyMMddHHmmss}_{Guid.NewGuid():N}.log |
| | 25 | | var logFilePath = Path.Combine(_applicationPaths.LogDirectoryPath, fileName); |
| | 26 | | var fileStream = new FileStream(logFilePath, FileMode.CreateNew, FileAccess.Write, FileShare.None); |
| | 27 | | await using (fileStream.ConfigureAwait(false)) |
| | 28 | | { |
| | 29 | | await fileContents.CopyToAsync(fileStream).ConfigureAwait(false); |
| | 30 | | return fileName; |
| | 31 | | } |
| | 32 | | } |
| | 33 | | } |
| | 34 | | } |