mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-12-17 22:43:07 +03:00
Add endpoint to log client events
This commit is contained in:
38
MediaBrowser.Controller/ClientEvent/ClientEventLogger.cs
Normal file
38
MediaBrowser.Controller/ClientEvent/ClientEventLogger.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using System;
|
||||
using MediaBrowser.Model.ClientLog;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace MediaBrowser.Controller.ClientEvent
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public class ClientEventLogger : IClientEventLogger
|
||||
{
|
||||
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;
|
||||
|
||||
/// <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)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Log(ClientLogEvent clientLogEvent)
|
||||
{
|
||||
_logger.Log(
|
||||
LogLevel.Critical,
|
||||
LogString,
|
||||
clientLogEvent.Timestamp,
|
||||
clientLogEvent.Level.ToString(),
|
||||
clientLogEvent.ClientName,
|
||||
clientLogEvent.ClientVersion,
|
||||
clientLogEvent.UserId ?? Guid.Empty,
|
||||
clientLogEvent.DeviceId,
|
||||
Environment.NewLine,
|
||||
clientLogEvent.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user