mirror of
https://github.com/hmaxnl/SharpRSS.git
synced 2025-01-18 21:04:21 +01:00
Reworked logging
This commit is contained in:
parent
654e2ef364
commit
a4788dbd02
|
@ -159,6 +159,7 @@ namespace SharpRss
|
|||
public static async Task<bool> DeleteSyndicationAsync(SyndicationModel syndication, bool deleteItems = false)
|
||||
{
|
||||
if (syndication == null) return false;
|
||||
Log.Information("Removing syndication...");
|
||||
await using SqliteConnection dbc = new SqliteConnection(ConnectionString);
|
||||
int affected = await dbc.ExecuteAsync("DELETE FROM syndication WHERE encoded_url=@EncodedUrl", new { EncodedUrl = syndication.EncodedUrl });
|
||||
if (affected > 0 && deleteItems)
|
||||
|
@ -168,6 +169,7 @@ namespace SharpRss
|
|||
|
||||
public static async Task SetSyndicationItemsAsync(HashSet<SyndicationItemModel> items)
|
||||
{
|
||||
Log.Information("Inserting syndication items...");
|
||||
await using SqliteConnection dbc = new SqliteConnection(ConnectionString);
|
||||
dbc.Open();
|
||||
int totalAffected = 0;
|
||||
|
@ -227,7 +229,7 @@ namespace SharpRss
|
|||
syndicationItemModel.SyndicationParent = TempCache.GetSyndication(syndicationItemModel.EncodedSyndicationUrl) ?? new SyndicationModel(); // The new syndication should never be initialized, if this hits then the date is not valid for some reason!!!
|
||||
items.Add(syndicationItemModel);
|
||||
}
|
||||
Log.Debug("Fetching feed items resulted: {ItemCount} item(s)", items.Count);
|
||||
Log.Information("Fetching feed items resulted: {ItemCount} item(s)", items.Count);
|
||||
return items;
|
||||
}
|
||||
public static async void Initialize()
|
||||
|
@ -236,15 +238,15 @@ namespace SharpRss
|
|||
Log.Verbose("Checking database...");
|
||||
await using SqliteConnection dbc = new SqliteConnection(ConnectionString);
|
||||
dbc.Open();
|
||||
Log.Verbose("Checking table: {Table}", "category");
|
||||
Log.Information("Checking table: {Table}", "category");
|
||||
await dbc.ExecuteAsync("CREATE TABLE IF NOT EXISTS category (id STRING PRIMARY KEY, name STRING NOT NULL, hex_color STRING NOT NULL, icon STRING, last_updated INT)");
|
||||
|
||||
Log.Verbose("Checking table: {Table}", "feed");
|
||||
Log.Information("Checking table: {Table}", "feed");
|
||||
await dbc.ExecuteAsync("CREATE TABLE IF NOT EXISTS syndication (encoded_url STRING PRIMARY KEY, title STRING, category_id STRING, syndication_type STRING, version STRING, description STRING, language STRING, copyright STRING, last_updated INT, publication_date INT, syn_updated_date INT, categories STRING, image_url STRING)");
|
||||
|
||||
Log.Verbose("Checking table: {Table}", "feed_item");
|
||||
Log.Information("Checking table: {Table}", "feed_item");
|
||||
await dbc.ExecuteAsync("CREATE TABLE IF NOT EXISTS syndication_item (link STRING PRIMARY KEY, encoded_syndication_url STRING, read STRING, type STRING, title STRING, description STRING, last_updated INT, item_updated_date INT, publishing_date INT, authors STRING, categories STRING, content STRING, comments_url STRING)");
|
||||
Log.Verbose("Checking database done!");
|
||||
Log.Information("Checking database done!");
|
||||
_isInitialized = true;
|
||||
}
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@ namespace SharpRss.Services
|
|||
{
|
||||
public SyndicationService()
|
||||
{
|
||||
Log.Information("Constructing SyndicationService...");
|
||||
SetupTestCategoriesAndFeedsAsync();
|
||||
}
|
||||
|
||||
|
@ -34,7 +35,7 @@ namespace SharpRss.Services
|
|||
var syndication = SyndicationManager.CreateSyndication(url);
|
||||
if (!syndication.Fetched)
|
||||
{
|
||||
Log.Debug("Failed to fetch syndication feed!");
|
||||
Log.Warning("Failed to fetch syndication feed!");
|
||||
return false;
|
||||
}
|
||||
if (category != null)
|
||||
|
@ -51,7 +52,7 @@ namespace SharpRss.Services
|
|||
}
|
||||
public async Task UpdateFeeds()
|
||||
{
|
||||
Log.Verbose("Fetching feeds...");
|
||||
Log.Information("Fetching feeds...");
|
||||
var feeds = await GetFeedsAsync();
|
||||
}
|
||||
public async Task<HashSet<SyndicationModel>> GetFeedsAsync(string? categoryId = null) => await DbAccess.GetSyndicationsAsync(categoryId == null ? null : new[]{ categoryId });
|
||||
|
@ -103,7 +104,8 @@ namespace SharpRss.Services
|
|||
}
|
||||
private async void SetupTestCategoriesAndFeedsAsync()
|
||||
{
|
||||
/*try
|
||||
Log.Information("Setting up test data...");
|
||||
try
|
||||
{
|
||||
CategoryModel? newsCategory = await CreateCategoryAsync(new CategoryModel() { Name = "News" });
|
||||
if (newsCategory != null)
|
||||
|
@ -142,7 +144,7 @@ namespace SharpRss.Services
|
|||
catch (Exception e)
|
||||
{
|
||||
Log.Error(e, "Exception!");
|
||||
}*/
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -27,7 +27,7 @@ namespace SharpRss
|
|||
Uri feedUri = new Uri(feedUrl);
|
||||
try
|
||||
{
|
||||
Log.Debug("Fetching syndication: {SyndicationUri}", feedUri.ToString());
|
||||
Log.Information("Fetching syndication: {SyndicationUri}", feedUri.ToString());
|
||||
syndicationFeed = GenericSyndicationFeed.Create(feedUri);
|
||||
}
|
||||
catch (Exception e)
|
||||
|
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user