diff --git a/src/ApplicationCore/Interfaces/IAppLogger.cs b/src/ApplicationCore/Interfaces/IAppLogger.cs new file mode 100644 index 0000000..1ae198d --- /dev/null +++ b/src/ApplicationCore/Interfaces/IAppLogger.cs @@ -0,0 +1,7 @@ +namespace ApplicationCore.Interfaces +{ + public interface IAppLogger + { + void LogWarning(string message, params object[] args); + } +} diff --git a/src/ApplicationCore/Interfaces/IImageService.cs b/src/ApplicationCore/Interfaces/IImageService.cs index ae41333..d2d01c7 100644 --- a/src/ApplicationCore/Interfaces/IImageService.cs +++ b/src/ApplicationCore/Interfaces/IImageService.cs @@ -1,16 +1,7 @@ -using ApplicationCore.Entities; -using Microsoft.eShopWeb.ApplicationCore.Entities; -using System.Security.Principal; -using System.Threading.Tasks; - -namespace ApplicationCore.Interfaces +namespace ApplicationCore.Interfaces { - public interface IImageService { byte[] GetImageBytesById(int id); } - - - } diff --git a/src/Infrastructure/Logging/LoggerAdapter.cs b/src/Infrastructure/Logging/LoggerAdapter.cs new file mode 100644 index 0000000..b79e843 --- /dev/null +++ b/src/Infrastructure/Logging/LoggerAdapter.cs @@ -0,0 +1,18 @@ +using ApplicationCore.Interfaces; +using Microsoft.Extensions.Logging; + +namespace Infrastructure.Logging +{ + public class LoggerAdapter : IAppLogger + { + private readonly ILogger _logger; + public LoggerAdapter(ILoggerFactory loggerFactory) + { + _logger = loggerFactory.CreateLogger(); + } + public void LogWarning(string message, params object[] args) + { + _logger.LogWarning(message, args); + } + } +} diff --git a/src/Web/Controllers/CatalogController.cs b/src/Web/Controllers/CatalogController.cs index eb64454..c414e68 100644 --- a/src/Web/Controllers/CatalogController.cs +++ b/src/Web/Controllers/CatalogController.cs @@ -15,12 +15,12 @@ namespace Microsoft.eShopWeb.Controllers private readonly IHostingEnvironment _env; private readonly ICatalogService _catalogService; private readonly IImageService _imageService; - private readonly ILogger _logger; + private readonly IAppLogger _logger; public CatalogController(IHostingEnvironment env, ICatalogService catalogService, IImageService imageService, - ILogger logger) + IAppLogger logger) { _env = env; _catalogService = catalogService; diff --git a/src/Web/Startup.cs b/src/Web/Startup.cs index 6ec6990..7c2f2ed 100644 --- a/src/Web/Startup.cs +++ b/src/Web/Startup.cs @@ -13,6 +13,7 @@ using System.Text; using Microsoft.AspNetCore.Http; using ApplicationCore.Interfaces; using Infrastructure.FileSystem; +using Infrastructure.Logging; namespace Microsoft.eShopWeb { @@ -68,6 +69,7 @@ namespace Microsoft.eShopWeb services.AddScoped(); services.Configure(Configuration); services.AddSingleton(); + services.AddScoped(typeof(IAppLogger<>), typeof(LoggerAdapter<>)); services.AddMvc(); _services = services; diff --git a/tests/UnitTests/Web/Controllers/CatalogControllerGetImage.cs b/tests/UnitTests/Web/Controllers/CatalogControllerGetImage.cs index a16b695..2c65931 100644 --- a/tests/UnitTests/Web/Controllers/CatalogControllerGetImage.cs +++ b/tests/UnitTests/Web/Controllers/CatalogControllerGetImage.cs @@ -12,7 +12,7 @@ namespace UnitTests public class CatalogControllerGetImage { private Mock _mockImageService = new Mock(); - private Mock> _mockLogger = new Mock>(); + private Mock> _mockLogger = new Mock>(); private CatalogController _controller; private int _testImageId = 123; private byte[] _testBytes = { 0x01, 0x02, 0x03 };