We can now save a query to the JSON file on disk now - for our cheap persistence layer
This commit is contained in:
@@ -18,6 +18,11 @@ namespace Umbraco.Core.Logging.Viewer
|
||||
/// </summary>
|
||||
IEnumerable<SavedLogSearch> GetSavedSearches();
|
||||
|
||||
/// <summary>
|
||||
/// Adds a new saved search to chosen datasource
|
||||
/// </summary>
|
||||
IEnumerable<SavedLogSearch> AddSavedSearch(string name, string query);
|
||||
|
||||
/// <summary>
|
||||
/// A count of number of errors
|
||||
/// By counting Warnings with Exceptions, Errors & Fatal messages
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Newtonsoft.Json;
|
||||
using Serilog.Events;
|
||||
using Serilog.Formatting.Compact.Reader;
|
||||
@@ -65,5 +66,31 @@ namespace Umbraco.Core.Logging.Viewer
|
||||
var rawJson = File.ReadAllText(path);
|
||||
return JsonConvert.DeserializeObject<IEnumerable<SavedLogSearch>>(rawJson);
|
||||
}
|
||||
|
||||
public override IEnumerable<SavedLogSearch> AddSavedSearch(string name, string query)
|
||||
{
|
||||
//Get the existing items
|
||||
var searches = GetSavedSearches().ToList();
|
||||
|
||||
//Add the new item to the bottom of the list
|
||||
searches.Add(new SavedLogSearch { Name = name, Query = query });
|
||||
|
||||
//Serilaize to JSON string
|
||||
var rawJson = JsonConvert.SerializeObject(searches, Formatting.Indented);
|
||||
|
||||
//Open file & save contents
|
||||
var path = IOHelper.MapPath("~/Config/logviewer.searches.config.js");
|
||||
|
||||
//If file does not exist - lets create it with an empty array
|
||||
IOHelper.EnsureFileExists(path, "[]");
|
||||
|
||||
//Write it back down to file
|
||||
File.WriteAllText(path, rawJson);
|
||||
|
||||
//Return the updated object - so we can instantly reset the entire array from the API response
|
||||
//As opposed to push a new item into the array
|
||||
return searches;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,8 @@ namespace Umbraco.Core.Logging.Viewer
|
||||
|
||||
public abstract IEnumerable<SavedLogSearch> GetSavedSearches();
|
||||
|
||||
public abstract IEnumerable<SavedLogSearch> AddSavedSearch(string name, string query);
|
||||
|
||||
public int GetNumberOfErrors(DateTimeOffset startDate, DateTimeOffset endDate)
|
||||
{
|
||||
var logs = GetAllLogs(startDate, endDate);
|
||||
|
||||
Reference in New Issue
Block a user