diff --git a/SharpRSS.sln b/SharpRSS.sln index f26a4d9..7dd82e5 100644 --- a/SharpRSS.sln +++ b/SharpRSS.sln @@ -11,6 +11,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ToolQit", "ToolQit\ToolQit\ EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharpSyndicationApi", "SharpSyndicationApi\SharpSyndicationApi.csproj", "{349033BA-F5C3-4CDB-AFEA-9E85711FFBD5}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ToolQit.Logging.Serilog", "..\ToolQit\ToolQit.Logging.Serilog\ToolQit.Logging.Serilog.csproj", "{E040C5E3-8847-41B8-8AE4-D6DE6E33F9BA}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -33,6 +35,10 @@ Global {349033BA-F5C3-4CDB-AFEA-9E85711FFBD5}.Debug|Any CPU.Build.0 = Debug|Any CPU {349033BA-F5C3-4CDB-AFEA-9E85711FFBD5}.Release|Any CPU.ActiveCfg = Release|Any CPU {349033BA-F5C3-4CDB-AFEA-9E85711FFBD5}.Release|Any CPU.Build.0 = Release|Any CPU + {E040C5E3-8847-41B8-8AE4-D6DE6E33F9BA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E040C5E3-8847-41B8-8AE4-D6DE6E33F9BA}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E040C5E3-8847-41B8-8AE4-D6DE6E33F9BA}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E040C5E3-8847-41B8-8AE4-D6DE6E33F9BA}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/SharpRss/DbAccess.cs b/SharpRss/DbAccess.cs index d5b9b82..621156c 100644 --- a/SharpRss/DbAccess.cs +++ b/SharpRss/DbAccess.cs @@ -6,9 +6,10 @@ using System.Linq; using System.Threading.Tasks; using Dapper; using Microsoft.Data.Sqlite; -using Serilog; using SharpRss.Core.Cache; using SharpRss.Models; +using ToolQit; +using ToolQit.Logging; namespace SharpRss { @@ -21,6 +22,7 @@ namespace SharpRss } internal static class DbAccess { + private static readonly ILog _log = LogManager.CreateLogger(typeof(DbAccess)); private static readonly string ConnectionString = $"Data Source={Path.Combine(Environment.CurrentDirectory, "sharp_rss.sqlite")};"; private static bool _isInitialized; @@ -129,7 +131,7 @@ namespace SharpRss ImageUrl = syndication.ImageUrl ?? string.Empty }); if (affected == 0) - Log.Warning("Failed to add feed: {FeedUrl}", syndication.EncodedUrl); + _log.Warning("Failed to add feed: {FeedUrl}", syndication.EncodedUrl); } public static async Task> GetSyndicationsAsync(string[]? categoryIds = null) { @@ -165,7 +167,7 @@ namespace SharpRss public static async Task DeleteSyndicationAsync(SyndicationModel syndication, bool deleteItems = false) { if (syndication == null) return false; - Log.Information("Removing syndication..."); + _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) @@ -175,7 +177,7 @@ namespace SharpRss public static async Task SetSyndicationItemsAsync(HashSet items) { - Log.Information("Inserting syndication items..."); + _log.Information("Inserting syndication items..."); await using SqliteConnection dbc = new SqliteConnection(ConnectionString); dbc.Open(); int totalAffected = 0; @@ -237,25 +239,25 @@ 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.Information("Fetching feed items resulted: {ItemCount} item(s)", items.Count); + _log.Information("Fetching feed items resulted: {ItemCount} item(s)", items.Count); state.Items = items; return true; } public static async void Initialize() { if (_isInitialized) return; - Log.Verbose("Checking database..."); + _log.Verbose("Checking database..."); await using SqliteConnection dbc = new SqliteConnection(ConnectionString); dbc.Open(); - Log.Information("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.Information("Checking table: {Table}", "syndication"); + _log.Information("Checking table: {Table}", "syndication"); 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.Information("Checking table: {Table}", "syndication_item"); + _log.Information("Checking table: {Table}", "syndication_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.Information("Checking database done!"); + _log.Information("Checking database done!"); _isInitialized = true; } diff --git a/SharpRss/Services/SyndicationService.cs b/SharpRss/Services/SyndicationService.cs index 421c751..d3d66fb 100644 --- a/SharpRss/Services/SyndicationService.cs +++ b/SharpRss/Services/SyndicationService.cs @@ -3,8 +3,9 @@ using System.Collections.Generic; using System.Threading.Tasks; using Argotic.Common; using Argotic.Syndication; -using Serilog; using SharpRss.Models; +using ToolQit; +using ToolQit.Logging; namespace SharpRss.Services { @@ -13,9 +14,11 @@ namespace SharpRss.Services /// public class SyndicationService { + private readonly ILog _log; public SyndicationService() { - Log.Information("Constructing SyndicationService..."); + _log = LogManager.CreateLogger(typeof(SyndicationService)); + _log.Information("Constructing SyndicationService..."); Task.Run(async () => await SetupTestCategoriesAndFeedsAsync()); } @@ -47,7 +50,7 @@ namespace SharpRss.Services var syndication = SyndicationManager.CreateSyndication(url); if (!syndication.Fetched) { - Log.Warning("Failed to fetch syndication feed!"); + _log.Warning("Failed to fetch syndication feed!"); return false; } if (category != null) @@ -58,13 +61,13 @@ namespace SharpRss.Services } catch (Exception e) { - Log.Error(e,"Error adding syndication: {FeedUrl} to database!", url); + _log.Error(e,"Error adding syndication: {FeedUrl} to database!", url); } return true; } public async Task UpdateFeeds() { - Log.Information("Fetching..."); + _log.Information("Fetching..."); var feeds = await GetSyndicationsAsync(); } public async Task> GetSyndicationsAsync(string? categoryId = null) => await DbAccess.GetSyndicationsAsync(categoryId == null ? null : new[]{ categoryId }); @@ -79,7 +82,7 @@ namespace SharpRss.Services - private static SyndicationModel FromResource(ISyndicationResource resource) + /*private static SyndicationModel FromResource(ISyndicationResource resource) { SyndicationModel model = new SyndicationModel(); switch (resource.Format) @@ -98,26 +101,26 @@ namespace SharpRss.Services AtomFeed atomFeed = (AtomFeed)resource; break; default: - Log.Information("Syndication implementation missing!"); + _log.Information("Syndication implementation missing!"); break; } return model; - } + }*/ private GenericSyndicationFeed? CreateSyndication(string url) { Uri feedUri = new Uri(url); - Log.Verbose("Checking syndication: {FeedUrl}", feedUri.ToString()); + _log.Verbose("Checking syndication: {FeedUrl}", feedUri.ToString()); if (!SyndicationDiscoveryUtility.UriExists(feedUri)) { - Log.Warning("Syndication: {FeedUri} does not exists!", feedUri.ToString()); + _log.Warning("Syndication: {FeedUri} does not exists!", feedUri.ToString()); return null; } - Log.Verbose("Fetching syndication: {FeedUrl}", feedUri.ToString()); + _log.Verbose("Fetching syndication: {FeedUrl}", feedUri.ToString()); return GenericSyndicationFeed.Create(new Uri(url)); } private async Task SetupTestCategoriesAndFeedsAsync() { - Log.Information("Setting up test data..."); + _log.Information("Setting up test data..."); try { CategoryModel? newsCategory = await CreateCategoryAsync(new CategoryModel() { Name = "News", Icon = ""}); @@ -156,7 +159,7 @@ namespace SharpRss.Services } catch (Exception e) { - Log.Error(e, "Exception!"); + _log.Error(e, "Exception!"); } } } diff --git a/SharpRss/SyndicationManager.cs b/SharpRss/SyndicationManager.cs index 42df166..36f0887 100644 --- a/SharpRss/SyndicationManager.cs +++ b/SharpRss/SyndicationManager.cs @@ -6,8 +6,9 @@ using System.Text; using Argotic.Common; using Argotic.Extensions.Core; using Argotic.Syndication; -using Serilog; using SharpRss.Models; +using ToolQit; +using ToolQit.Logging; namespace SharpRss { @@ -21,18 +22,19 @@ namespace SharpRss } public static class SyndicationManager { + private static ILog _log = LogManager.CreateLogger(typeof(SyndicationManager)); public static SyndicationContainer CreateSyndication(string feedUrl) { GenericSyndicationFeed? syndicationFeed = null; Uri feedUri = new Uri(feedUrl); try { - Log.Information("Fetching syndication: {SyndicationUri}", feedUri.ToString()); + _log.Information("Fetching syndication: {SyndicationUri}", feedUri.ToString()); syndicationFeed = GenericSyndicationFeed.Create(feedUri); } catch (Exception e) { - Log.Error(e,"Could not get syndication: {SyndicationUrl}", feedUrl); + _log.Error(e,"Could not get syndication: {SyndicationUrl}", feedUrl); } return ConstructSyndicationContainer(syndicationFeed, feedUrl); } @@ -42,7 +44,7 @@ namespace SharpRss MemoryStream memStream = new MemoryStream(); syndicationFeed.Resource.Save(memStream); if (memStream.Length <= 0) - Log.Warning("Failed to serialize {SyndicationType} feed: {SyndicationUri}", syndicationFeed.Format.ToString(), syndicationFeed.Title); + _log.Warning("Failed to serialize {SyndicationType} feed: {SyndicationUri}", syndicationFeed.Format.ToString(), syndicationFeed.Title); memStream.Position = 0; return memStream; } @@ -52,7 +54,7 @@ namespace SharpRss SyndicationContainer container = new SyndicationContainer(); if (syndicationFeed == null) { - Log.Error("Could not construct syndication container!"); + _log.Warning("Could not construct syndication container!"); return container; } container.SyndicationFeed = syndicationFeed; @@ -122,7 +124,7 @@ namespace SharpRss } break; default: - Log.Warning("Syndication implementation missing!"); + _log.Warning("Syndication implementation missing!"); break; } container.Fetched = true; diff --git a/ToolQit b/ToolQit index d8bd813..4983d45 160000 --- a/ToolQit +++ b/ToolQit @@ -1 +1 @@ -Subproject commit d8bd813a7261ffd2d8923606d6362644a8e8c6de +Subproject commit 4983d4524cbdc424a9e0d8754eb5889f36450b79 diff --git a/WebSharpRSS/Bootstrapper.cs b/WebSharpRSS/Bootstrapper.cs index ff52262..e4a7ad5 100644 --- a/WebSharpRSS/Bootstrapper.cs +++ b/WebSharpRSS/Bootstrapper.cs @@ -5,6 +5,8 @@ using Serilog.Formatting.Json; using SharpRss; using ToolQit; using ToolQit.Containers; +using ToolQit.Logging; +using ToolQit.Logging.Serilog; namespace WebSharpRSS { @@ -12,6 +14,7 @@ namespace WebSharpRSS { private static bool _defaultsSet; private static bool _bootstrapped; + private static readonly ILog Log = LogManager.CreateLogger(typeof(Bootstrapper)); public static void Bootstrap() { @@ -38,12 +41,14 @@ namespace WebSharpRSS if (!_defaultsSet) throw new Exception("Bootstrapper defaults are not initialized!"); if (_configuration != null) return; _configuration = new LoggerConfiguration() - .WriteTo.Console() + .Enrich.With(new LogEnricher()) + .WriteTo.Console(outputTemplate: "[{Timestamp:HH:mm:ss} - {Sender} | {Level:u3}] {Message:lj}{NewLine}{Exception}") .WriteTo.File(new JsonFormatter(), Caretaker.Settings["Paths"].GetString("LogPath"), rollingInterval: RollingInterval.Day); /*.MinimumLevel.Verbose(); // ONLY FOR DEBUGGING!!!*/ - Log.Logger = _configuration.CreateLogger(); + Serilog.Log.Logger = _configuration.CreateLogger(); + LogManager.RegisterAdapter(new SerilogAdapter(Serilog.Log.Logger)); } } } \ No newline at end of file diff --git a/WebSharpRSS/WebSharpRSS.csproj b/WebSharpRSS/WebSharpRSS.csproj index 6f325c8..419fa4c 100644 --- a/WebSharpRSS/WebSharpRSS.csproj +++ b/WebSharpRSS/WebSharpRSS.csproj @@ -22,6 +22,7 @@ + diff --git a/WebSharpRSS/sharp_rss.sqlite b/WebSharpRSS/sharp_rss.sqlite index 9569dac..30fb42c 100644 Binary files a/WebSharpRSS/sharp_rss.sqlite and b/WebSharpRSS/sharp_rss.sqlite differ diff --git a/git-cmd.md b/git-cmd.md new file mode 100644 index 0000000..3e4ba00 --- /dev/null +++ b/git-cmd.md @@ -0,0 +1,3 @@ + +## Update all submoduels +git submodule update --remote --merge