mirror of
https://github.com/lidarr/lidarr.git
synced 2025-08-21 14:03:29 -07:00
LogProvider now usues petapoco
This commit is contained in:
parent
335639fabc
commit
f4801901a7
8 changed files with 234 additions and 157 deletions
|
@ -1,14 +1,16 @@
|
|||
using System;
|
||||
using PetaPoco;
|
||||
using SubSonic.SqlGeneration.Schema;
|
||||
|
||||
namespace NzbDrone.Core.Instrumentation
|
||||
{
|
||||
[TableName("Logs")]
|
||||
[PrimaryKey("LogId", autoIncrement = true)]
|
||||
public class Log
|
||||
{
|
||||
[SubSonicPrimaryKey]
|
||||
public int LogId { get; protected set; }
|
||||
|
||||
[SubSonicLongString]
|
||||
public Int64 LogId { get; protected set; }
|
||||
|
||||
public string Message { get; set; }
|
||||
|
||||
public DateTime Time { get; set; }
|
||||
|
@ -17,11 +19,8 @@ namespace NzbDrone.Core.Instrumentation
|
|||
|
||||
public string Method { get; set; }
|
||||
|
||||
[SubSonicNullString]
|
||||
[SubSonicLongString]
|
||||
public string Exception { get; set; }
|
||||
|
||||
[SubSonicNullString]
|
||||
public string ExceptionType { get; set; }
|
||||
|
||||
public String Level { get; set; }
|
||||
|
|
|
@ -1,27 +1,31 @@
|
|||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NLog;
|
||||
using PetaPoco;
|
||||
using SubSonic.Repository;
|
||||
|
||||
namespace NzbDrone.Core.Instrumentation
|
||||
{
|
||||
public class LogProvider
|
||||
{
|
||||
private readonly IDatabase _database;
|
||||
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
||||
private readonly IRepository _repository;
|
||||
|
||||
public LogProvider(IRepository repository)
|
||||
|
||||
|
||||
public LogProvider(IDatabase database)
|
||||
{
|
||||
_repository = repository;
|
||||
_database = database;
|
||||
}
|
||||
|
||||
public IQueryable<Log> GetAllLogs()
|
||||
public IList<Log> GetAllLogs()
|
||||
{
|
||||
return _repository.All<Log>();
|
||||
return _database.Fetch<Log>();
|
||||
}
|
||||
|
||||
public void DeleteAll()
|
||||
{
|
||||
_repository.DeleteMany(GetAllLogs());
|
||||
_database.Delete<Log>("");
|
||||
Logger.Info("Cleared Log History");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,17 +1,18 @@
|
|||
using System;
|
||||
using NLog;
|
||||
using NLog.Targets;
|
||||
using PetaPoco;
|
||||
using SubSonic.Repository;
|
||||
|
||||
namespace NzbDrone.Core.Instrumentation
|
||||
{
|
||||
public class SubsonicTarget : Target
|
||||
{
|
||||
private readonly IRepository _repository;
|
||||
private readonly IDatabase _database;
|
||||
|
||||
public SubsonicTarget(IRepository repository)
|
||||
public SubsonicTarget(IDatabase database)
|
||||
{
|
||||
_repository = repository;
|
||||
_database = database;
|
||||
}
|
||||
|
||||
protected override void Write(LogEventInfo logEvent)
|
||||
|
@ -47,7 +48,7 @@ namespace NzbDrone.Core.Instrumentation
|
|||
log.Level = logEvent.Level.Name;
|
||||
|
||||
|
||||
_repository.Add(log);
|
||||
_database.Insert(log);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue