Radarr/NzbDrone.Web/Controllers/LogController.cs

76 lines
2.3 KiB
C#
Raw Normal View History

2012-01-23 02:24:16 +00:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Dynamic;
2012-01-23 02:24:16 +00:00
using System.Text;
using System.Web.Mvc;
using DataTables.Mvc.Core;
using DataTables.Mvc.Core.Models;
2012-01-23 02:24:16 +00:00
using NzbDrone.Common;
using NzbDrone.Core.Instrumentation;
2011-08-22 01:00:12 +00:00
using NzbDrone.Web.Models;
namespace NzbDrone.Web.Controllers
{
public class LogController : Controller
{
private readonly LogProvider _logProvider;
private readonly EnvironmentProvider _environmentProvider;
2012-01-23 02:24:16 +00:00
private readonly DiskProvider _diskProvider;
2012-04-21 08:16:15 +00:00
public LogController(LogProvider logProvider, EnvironmentProvider environmentProvider,
DiskProvider diskProvider)
{
_logProvider = logProvider;
_environmentProvider = environmentProvider;
2012-01-23 02:24:16 +00:00
_diskProvider = diskProvider;
}
2012-01-23 02:24:16 +00:00
public FileContentResult File()
{
string log = string.Empty;
if (_diskProvider.FileExists(_environmentProvider.GetArchivedLogFileName()))
2012-01-23 02:24:16 +00:00
{
log = _diskProvider.ReadAllText(_environmentProvider.GetArchivedLogFileName());
2012-01-23 02:24:16 +00:00
}
log += _diskProvider.ReadAllText(_environmentProvider.GetLogFileName());
2012-01-23 02:24:16 +00:00
return new FileContentResult(Encoding.ASCII.GetBytes(log), "text/plain");
}
public JsonResult Clear()
{
_logProvider.DeleteAll();
return JsonNotificationResult.Info("Logs Cleared");
}
public ActionResult AjaxBinding(DataTablesPageRequest pageRequest)
{
2013-01-08 08:57:38 +00:00
var pageResult = _logProvider.GetPagedItems(pageRequest);
var totalItems = _logProvider.Count();
2013-01-08 08:57:38 +00:00
var items = pageResult.Items.Select(l => new LogModel
{
2013-01-08 08:57:38 +00:00
Time = l.Time.ToString(),
Level = l.Level,
Source = l.Logger,
Message = l.Message,
Method = l.Method,
ExceptionType = l.ExceptionType,
Exception = l.Exception
});
return Json(new
{
sEcho = pageRequest.Echo,
2013-01-08 08:57:38 +00:00
iTotalRecords = totalItems,
iTotalDisplayRecords = pageResult.TotalItems,
aaData = items
},
JsonRequestBehavior.AllowGet);
}
}
2011-04-10 02:44:01 +00:00
}