2021-04-26 13:02:26 +00:00
|
|
|
|
using System;
|
2021-10-27 00:42:17 +00:00
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Threading.Tasks;
|
2021-04-26 13:02:26 +00:00
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Controller.ClientEvent
|
|
|
|
|
{
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
public class ClientEventLogger : IClientEventLogger
|
|
|
|
|
{
|
2021-10-27 00:42:17 +00:00
|
|
|
|
private readonly IServerApplicationPaths _applicationPaths;
|
2021-04-26 13:02:26 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Initializes a new instance of the <see cref="ClientEventLogger"/> class.
|
|
|
|
|
/// </summary>
|
2021-10-27 00:42:17 +00:00
|
|
|
|
/// <param name="applicationPaths">Instance of the <see cref="IServerApplicationPaths"/> interface.</param>
|
2021-11-20 15:47:05 +00:00
|
|
|
|
public ClientEventLogger(IServerApplicationPaths applicationPaths)
|
2021-04-26 13:02:26 +00:00
|
|
|
|
{
|
2021-10-27 00:42:17 +00:00
|
|
|
|
_applicationPaths = applicationPaths;
|
2021-04-26 13:02:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-10-27 00:42:17 +00:00
|
|
|
|
/// <inheritdoc />
|
2021-11-05 16:40:45 +00:00
|
|
|
|
public async Task<string> WriteDocumentAsync(string clientName, string clientVersion, Stream fileContents)
|
2021-10-27 00:42:17 +00:00
|
|
|
|
{
|
2021-11-07 18:41:56 +00:00
|
|
|
|
var fileName = $"upload_{clientName}_{clientVersion}_{DateTime.UtcNow:yyyyMMddHHmmss}_{Guid.NewGuid():N}.log";
|
2021-10-27 00:42:17 +00:00
|
|
|
|
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);
|
2021-10-28 22:11:14 +00:00
|
|
|
|
return fileName;
|
2021-10-27 00:42:17 +00:00
|
|
|
|
}
|
2021-04-26 13:02:26 +00:00
|
|
|
|
}
|
2021-10-27 00:42:17 +00:00
|
|
|
|
}
|