Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update log messages #28

Merged
merged 3 commits into from
Mar 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -32,7 +32,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 @@ -74,6 +74,7 @@ public async Task StartAsync(CancellationToken stoppingToken)

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