mirror of
https://github.com/Jackett/Jackett.git
synced 2025-09-17 17:34:09 +02:00
logging: cleanse messages in log files (#14433)
Co-authored-by: ilike2burnthing <59480337+ilike2burnthing@users.noreply.github.com>
This commit is contained in:
@@ -2,43 +2,43 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Jackett.Common.Models;
|
||||
using Jackett.Common.Services.Interfaces;
|
||||
using Jackett.Common.Utils.Logging;
|
||||
using NLog;
|
||||
using NLog.Targets;
|
||||
|
||||
namespace Jackett.Common.Services
|
||||
{
|
||||
|
||||
[Target("LogService")]
|
||||
public class LogCacheService : TargetWithLayout, ILogCacheService
|
||||
{
|
||||
private static List<CachedLog> logs = new List<CachedLog>();
|
||||
|
||||
public void AddLog(LogEventInfo l)
|
||||
{
|
||||
lock (logs)
|
||||
{
|
||||
logs.Insert(0, new CachedLog()
|
||||
{
|
||||
Level = l.Level.Name,
|
||||
Message = l.FormattedMessage,
|
||||
When = l.TimeStamp
|
||||
});
|
||||
logs = logs.Take(200).ToList();
|
||||
}
|
||||
|
||||
}
|
||||
private static List<CachedLog> _Logs = new List<CachedLog>();
|
||||
|
||||
public List<CachedLog> Logs
|
||||
{
|
||||
get
|
||||
{
|
||||
lock (logs)
|
||||
lock (_Logs)
|
||||
{
|
||||
return logs.ToList();
|
||||
return _Logs.ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Write(LogEventInfo logEvent) => AddLog(logEvent);
|
||||
|
||||
private static void AddLog(LogEventInfo logEvent)
|
||||
{
|
||||
lock (_Logs)
|
||||
{
|
||||
_Logs.Insert(0, new CachedLog
|
||||
{
|
||||
Level = logEvent.Level.Name,
|
||||
Message = CleanseLogMessage.Cleanse(logEvent.FormattedMessage),
|
||||
When = logEvent.TimeStamp
|
||||
});
|
||||
|
||||
_Logs = _Logs.Take(200).ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user