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