|
|
@ -1,4 +1,6 @@
|
|
|
|
using System;
|
|
|
|
using System;
|
|
|
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
using MediaBrowser.Model.ClientLog;
|
|
|
|
using MediaBrowser.Model.ClientLog;
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
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 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 ILogger<ClientEventLogger> _logger;
|
|
|
|
|
|
|
|
private readonly IServerApplicationPaths _applicationPaths;
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// Initializes a new instance of the <see cref="ClientEventLogger"/> class.
|
|
|
|
/// Initializes a new instance of the <see cref="ClientEventLogger"/> class.
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="logger">Instance of the <see cref="ILogger{ClientEventLogger}"/> interface.</param>
|
|
|
|
/// <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;
|
|
|
|
_logger = logger;
|
|
|
|
|
|
|
|
_applicationPaths = applicationPaths;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
/// <inheritdoc />
|
|
|
@ -34,5 +41,16 @@ namespace MediaBrowser.Controller.ClientEvent
|
|
|
|
Environment.NewLine,
|
|
|
|
Environment.NewLine,
|
|
|
|
clientLogEvent.Message);
|
|
|
|
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);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|