1
0
Fork 0
mirror of https://github.com/lidarr/Lidarr synced 2024-12-30 19:45:57 +00:00
Lidarr/NzbDrone.Core/Instrumentation/LogProvider.cs

50 lines
1.4 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using NLog;
2011-06-18 00:11:12 +00:00
using PetaPoco;
namespace NzbDrone.Core.Instrumentation
{
public class LogProvider
{
2011-06-18 00:11:12 +00:00
private readonly IDatabase _database;
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
2011-06-18 00:11:12 +00:00
public LogProvider(IDatabase database)
{
2011-06-18 00:11:12 +00:00
_database = database;
}
2011-06-18 00:11:12 +00:00
public IList<Log> GetAllLogs()
{
2011-06-18 00:11:12 +00:00
return _database.Fetch<Log>();
}
public IList<Log> TopLogs(int count)
{
var logs = _database.Fetch<Log>("SELECT TOP " + count + " * FROM Logs ORDER BY Time Desc");
logs.Add(new Log
{
Time = DateTime.Now.AddYears(-100),
Level = "Info",
Logger = "Core.Instrumentation.LogProvider",
Message = String.Format("Number of logs currently shown: {0}. More may exist, check 'All' to see everything", Math.Min(count, logs.Count))
});
return logs;
}
public Page<Log> GetPagedLogs(int pageNumber, int pageSize)
{
return _database.Page<Log>(pageNumber, pageSize, "SELECT * FROM Logs ORDER BY Time DESC");
}
public void DeleteAll()
{
2011-06-18 00:11:12 +00:00
_database.Delete<Log>("");
Logger.Info("Cleared Log History");
}
}
2011-04-10 02:44:01 +00:00
}