Skip to content

Commit

Permalink
Merge pull request #28 from prplecake/update-logging
Browse files Browse the repository at this point in the history
  • Loading branch information
prplecake committed Mar 29, 2023
2 parents 94f0f42 + 25a8c4c commit e571f4f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions BookmarkSync.Core/BookmarkSync.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<PackageReference Include="Microsoft.Extensions.Configuration" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="7.0.4" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Serilog" Version="2.12.0" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="7.0.0" />
</ItemGroup>

Expand Down
6 changes: 5 additions & 1 deletion BookmarkSync.Core/Configuration/ConfigManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using BookmarkSync.Core.Entities.Config;
using CiT.Common.Exceptions;
using Microsoft.Extensions.Configuration;
using Serilog;

namespace BookmarkSync.Core.Configuration;

Expand All @@ -17,15 +18,17 @@ public interface IConfigManager
}
public class ConfigManager : IConfigManager
{
private static readonly ILogger _logger = Log.ForContext<ConfigManager>();
public ConfigManager(
IConfiguration configuration)
{
Configuration = configuration;
App = Configuration.GetSection("App").Get<App>() ?? throw new NullReferenceException();
App = Configuration.GetSection("App").Get<App>() ?? throw new InvalidOperationException();
Instances = Configuration.GetSection("Instances").Get<List<Instance>>();

if (!App.IsValid())
{
_logger.Error("App configuration is invalid");
throw new InvalidConfigurationException();
}
}
Expand All @@ -34,6 +37,7 @@ public ConfigManager(
public App App { get; set; }
public string GetConfigValue(string key)
{
_logger.Debug("Running {Method} for key: {Key}", "GetConfigValue", key);
string? value = Configuration[key];
if (string.IsNullOrWhiteSpace(value))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public async Task StartAsync(CancellationToken stoppingToken)
{
if (_instances == null || _instances.Count == 0)
{
_logger.Information("No instances configured");
_logger.Warning("No instances configured");
return;
}
foreach (var instance in _instances)
Expand Down Expand Up @@ -72,6 +72,7 @@ public async Task StartAsync(CancellationToken stoppingToken)

if (instance.DeleteBookmarks && result.IsSuccessStatusCode)
{
_logger.Information("Deleting bookmark");
await client.DeleteBookmark(bookmark);
}
}
Expand Down

0 comments on commit e571f4f

Please sign in to comment.