Skip to content

Commit ff202f8

Browse files
added initial log entries
1 parent ad845f6 commit ff202f8

File tree

3 files changed

+23
-10
lines changed

3 files changed

+23
-10
lines changed

CarvedRock.Api/Controllers/ProductController.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,19 @@ namespace CarvedRock.Api.Controllers;
88
[Route("[controller]")]
99
public class ProductController : ControllerBase
1010
{
11+
private readonly ILogger<ProductController> _logger;
1112
private readonly IProductLogic _productLogic;
1213

13-
public ProductController(IProductLogic productLogic)
14+
public ProductController(ILogger<ProductController> logger, IProductLogic productLogic)
1415
{
16+
_logger = logger;
1517
_productLogic = productLogic;
1618
}
1719

1820
[HttpGet]
1921
public async Task<IEnumerable<ProductModel>> Get(string category = "all")
2022
{
23+
_logger.LogInformation("Getting products in API for {category}", category);
2124
return await _productLogic.GetProductsForCategory(category);
2225
}
2326
}
Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
2-
3-
<PropertyGroup>
4-
<TargetFramework>net6.0</TargetFramework>
5-
<ImplicitUsings>enable</ImplicitUsings>
6-
<Nullable>enable</Nullable>
7-
</PropertyGroup>
8-
9-
</Project>
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<TargetFramework>net6.0</TargetFramework>
4+
<ImplicitUsings>enable</ImplicitUsings>
5+
<Nullable>enable</Nullable>
6+
</PropertyGroup>
7+
<ItemGroup>
8+
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.0"/>
9+
</ItemGroup>
10+
</Project>

CarvedRock.Domain/ProductLogic.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
using CarvedRock.Domain.Models;
2+
using Microsoft.Extensions.Logging;
23

34
namespace CarvedRock.Domain;
45

56
public class ProductLogic : IProductLogic
67
{
8+
private readonly ILogger<ProductLogic> _logger;
9+
10+
public ProductLogic(ILogger<ProductLogic> logger)
11+
{
12+
_logger = logger;
13+
}
714
public Task<IEnumerable<ProductModel>> GetProductsForCategory(string category)
815
{
16+
_logger.LogInformation("Getting products in logic for {category}", category);
17+
918
return Task.FromResult(GetAllProducts().Where(a =>
1019
string.Equals("all", category, StringComparison.InvariantCultureIgnoreCase) ||
1120
string.Equals(category, a.Category, StringComparison.InvariantCultureIgnoreCase)));

0 commit comments

Comments
 (0)