Skip to content

Commit

Permalink
Solution - Add Serilog.Sinks.
Browse files Browse the repository at this point in the history
  • Loading branch information
Stan-Kudri committed Oct 16, 2023
1 parent 5e9dc69 commit 9d59c1e
Show file tree
Hide file tree
Showing 19 changed files with 104 additions and 243 deletions.
45 changes: 0 additions & 45 deletions WatchList.Core/Logger/AggregateLogging.cs

This file was deleted.

35 changes: 0 additions & 35 deletions WatchList.Core/Logger/ConsoleLogger.cs

This file was deleted.

48 changes: 0 additions & 48 deletions WatchList.Core/Logger/FileLogger.cs

This file was deleted.

12 changes: 6 additions & 6 deletions WatchList.Core/Repository/WatchItemRepository.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using Serilog.Core;
using WatchList.Core.Model.ItemCinema;
using WatchList.Core.PageItem;
using WatchList.Core.Repository.Db;
Expand All @@ -10,9 +10,9 @@ namespace WatchList.Core.Repository
public class WatchItemRepository : IWatchItemRepository
{
private readonly WatchCinemaDbContext _db;
private readonly ILogger _logger;
private readonly Logger _logger;

public WatchItemRepository(WatchCinemaDbContext db, ILogger logger)
public WatchItemRepository(WatchCinemaDbContext db, Logger logger)
{
_db = db;
_logger = logger;
Expand All @@ -30,7 +30,7 @@ public void Add(WatchItem item)
item.Id = _db.ReplaceIdIsNotFree(item);
_db.Add(item);
_db.SaveChanges();
_logger.LogInformation("Add item with ID {0}", item.Id);
_logger.Information("Add item with ID {0}", item.Id);
}

public void Remove(Guid id)
Expand All @@ -41,7 +41,7 @@ public void Remove(Guid id)
throw new InvalidOperationException("Interaction element not found.");
}

_logger.LogInformation("Remove item with ID {0}", id);
_logger.Information("Remove item with ID {0}", id);
}

public void Update(WatchItem editItem)
Expand All @@ -62,7 +62,7 @@ public void Update(WatchItem editItem)

_db.SaveChanges();

_logger.LogInformation("Edit item with ID {0}", item.Id);
_logger.Information("Edit item with ID {0}", item.Id);
}

public List<Guid> SelectDuplicateItems(WatchItem item) =>
Expand Down
8 changes: 4 additions & 4 deletions WatchList.Core/Service/DataLoading/DownloadDataService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Microsoft.Extensions.Logging;
using Serilog.Core;
using WatchList.Core.Model.Filter;
using WatchList.Core.Model.QuestionResult;
using WatchList.Core.Model.Sorting;
Expand All @@ -13,9 +13,9 @@ public class DownloadDataService
{
private readonly WatchItemRepository _repository;
private readonly IMessageBox _messageBox;
private readonly ILogger _logger;
private readonly Logger _logger;

public DownloadDataService(WatchItemRepository repository, IMessageBox messageBox, ILogger logger, int numberOfItemPerPage = 500)
public DownloadDataService(WatchItemRepository repository, IMessageBox messageBox, Logger logger, int numberOfItemPerPage = 500)
{
_repository = repository;
_messageBox = messageBox;
Expand All @@ -35,7 +35,7 @@ public void Download(WatchItemRepository repository, ILoadRule loadRule)
var watchItemCollection = new WatchItemCollection(pagedList);
watchItemCollection = loadRule.Apply(watchItemCollection);

_logger.LogInformation("Load items according to selected rules");
_logger.Information("Load items according to selected rules");
AddItems(watchItemCollection);
UpdateItems(watchItemCollection);

Expand Down
2 changes: 2 additions & 0 deletions WatchList.Core/WatchList.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
<PackageReference Include="CassandraCSharpDriver" Version="3.18.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="7.0.7" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.1" />
<PackageReference Include="Serilog" Version="3.0.1" />
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
34 changes: 0 additions & 34 deletions WatchList.Test/CoreTest/TestLogger.cs

This file was deleted.

7 changes: 5 additions & 2 deletions WatchList.Test/CoreTest/WatchItemRepositoryTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using FluentAssertions;
using Serilog;
using WatchList.Core.Model.Filter;
using WatchList.Core.Model.Filter.Components;
using WatchList.Core.Model.ItemCinema;
Expand Down Expand Up @@ -71,7 +72,8 @@ public void Verifying_The_Use_Of_The_Database_Page_Get_Method(
{
// Arrange
var appDbContext = new TestAppDbContextFactory().Create();
var itemRepository = new WatchItemRepository(appDbContext, new TestLogger());
var testLoger = new LoggerConfiguration().WriteTo.TestCorrelator().CreateLogger();
var itemRepository = new WatchItemRepository(appDbContext, testLoger);
appDbContext.AddRange(watchItems);
appDbContext.SaveChanges();

Expand All @@ -92,7 +94,8 @@ public void Verifying_The_Use_Of_The_Update_Item_Method(
{
// Arrange
var appDbContext = new TestAppDbContextFactory().Create();
var itemRepository = new WatchItemRepository(appDbContext, new TestLogger());
var testLoger = new LoggerConfiguration().WriteTo.TestCorrelator().CreateLogger();
var itemRepository = new WatchItemRepository(appDbContext, testLoger);
var searchRequest = new WatchItemSearchRequest();
appDbContext.AddRange(watchItems);
appDbContext.SaveChanges();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using FluentAssertions;
using Moq;
using Serilog;
using WatchList.Core.Model.ItemCinema;
using WatchList.Core.Model.ItemCinema.Components;
using WatchList.Core.Repository;
Expand Down Expand Up @@ -58,7 +59,8 @@ public void Add_With_Replace_Duplicate_Element(List<WatchItem> items, WatchItem
{
// Arrange
var dbContext = new TestAppDbContextFactory().Create();
var itemRepository = new WatchItemRepository(dbContext, new TestLogger());
var testLoger = new LoggerConfiguration().WriteTo.TestCorrelator().CreateLogger();
var itemRepository = new WatchItemRepository(dbContext, testLoger);
var messageBox = new Mock<IMessageBox>();
messageBox.Setup(foo => foo.ShowQuestionSaveItem(WatchItemService.DuplicateReplaceMessage)).Returns(true);
var service = new WatchItemService(itemRepository, messageBox.Object);
Expand Down
Loading

0 comments on commit 9d59c1e

Please sign in to comment.