diff --git a/Chatbot.Api.Application/CommandHandlers/TestLoggerHandler.cs b/Chatbot.Api.Application/CommandHandlers/TestLoggerHandler.cs new file mode 100644 index 0000000..faea1a4 --- /dev/null +++ b/Chatbot.Api.Application/CommandHandlers/TestLoggerHandler.cs @@ -0,0 +1,34 @@ +using Chatbot.Api.Application.Commands; +using Chatbot.Api.Application.Events; +using MediatR; +using Microsoft.Extensions.Logging; +using System; +using System.Threading; +using System.Threading.Tasks; + +namespace Chatbot.Api.Application.CommandHandlers +{ + public class TestLoggerHandler : IRequestHandler + { + private readonly ILogger _logger; + + public TestLoggerHandler(ILogger logger) + { + _logger = logger; + } + + public async Task Handle(TestLogger request, CancellationToken cancellationToken) + { + _logger.LogDebug(TextToLog); + _logger.LogInformation(TextToLog); + _logger.LogWarning(TextToLog); + _logger.LogError(TextToLog); + _logger.LogCritical(TextToLog); + + await Task.Delay(1); + return new LoggerTested(); + } + + private string TextToLog => $"Logger test - {DateTime.Now}"; + } +} diff --git a/Chatbot.Api.Application/Commands/TestLogger.cs b/Chatbot.Api.Application/Commands/TestLogger.cs new file mode 100644 index 0000000..01ee9b2 --- /dev/null +++ b/Chatbot.Api.Application/Commands/TestLogger.cs @@ -0,0 +1,13 @@ +using Chatbot.Api.Application.Events; +using System; + +namespace Chatbot.Api.Application.Commands +{ + public class TestLogger : Command + { + public TestLogger() + : base(new Metadata() { CorrelationId = Guid.NewGuid() }) + { + } + } +} diff --git a/Chatbot.Api.Application/Events/LoggerTested.cs b/Chatbot.Api.Application/Events/LoggerTested.cs new file mode 100644 index 0000000..e1a7a73 --- /dev/null +++ b/Chatbot.Api.Application/Events/LoggerTested.cs @@ -0,0 +1,6 @@ +namespace Chatbot.Api.Application.Events +{ + public class LoggerTested + { + } +} diff --git a/Chatbot.Api/Controllers/SystemController.cs b/Chatbot.Api/Controllers/SystemController.cs index 3a3e7a0..389bd01 100644 --- a/Chatbot.Api/Controllers/SystemController.cs +++ b/Chatbot.Api/Controllers/SystemController.cs @@ -1,4 +1,5 @@ -using Chatbot.Api.Application.Queries; +using Chatbot.Api.Application.Commands; +using Chatbot.Api.Application.Queries; using MediatR; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; @@ -38,5 +39,12 @@ namespace Chatbot.Api.Controllers var result = await _mediator.Send(query); return Ok(result); } + + [HttpPost("test-logger")] + public async Task CloseChat([FromBody] TestLogger closeChat) + { + var result = await _mediator.Send(closeChat); + return Ok(result); + } } }