2015-08-06 19:07:58 +00:00
|
|
|
|
using Jackett.Models;
|
|
|
|
|
using NLog;
|
|
|
|
|
using NLog.Targets;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
2017-10-29 10:19:09 +00:00
|
|
|
|
using Jackett.Services.Interfaces;
|
2015-08-06 19:07:58 +00:00
|
|
|
|
|
|
|
|
|
namespace Jackett.Services
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
[Target("LogService")]
|
2017-11-05 09:42:03 +00:00
|
|
|
|
public class LogCacheService: TargetWithLayout, ILogCacheService
|
2015-08-06 19:07:58 +00:00
|
|
|
|
{
|
|
|
|
|
private static List<CachedLog> logs = new List<CachedLog>();
|
|
|
|
|
|
|
|
|
|
public void AddLog(LogEventInfo l)
|
|
|
|
|
{
|
|
|
|
|
lock (logs)
|
|
|
|
|
{
|
|
|
|
|
logs.Insert(0, new CachedLog()
|
|
|
|
|
{
|
|
|
|
|
Level = l.Level.Name,
|
2018-03-08 10:40:20 +00:00
|
|
|
|
Message = l.FormattedMessage,
|
2015-08-06 19:07:58 +00:00
|
|
|
|
When = l.TimeStamp
|
|
|
|
|
});
|
2015-08-07 21:40:45 +00:00
|
|
|
|
logs = logs.Take(50).ToList();
|
2015-08-06 19:07:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<CachedLog> Logs
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
lock (logs)
|
|
|
|
|
{
|
|
|
|
|
return logs.ToList();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void Write(LogEventInfo logEvent)
|
|
|
|
|
{
|
|
|
|
|
AddLog(logEvent);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|