test logger method
parent
5503a82241
commit
76045fe755
|
@ -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<TestLogger, LoggerTested>
|
||||
{
|
||||
private readonly ILogger<TestLoggerHandler> _logger;
|
||||
|
||||
public TestLoggerHandler(ILogger<TestLoggerHandler> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public async Task<LoggerTested> 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}";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
using Chatbot.Api.Application.Events;
|
||||
using System;
|
||||
|
||||
namespace Chatbot.Api.Application.Commands
|
||||
{
|
||||
public class TestLogger : Command<LoggerTested>
|
||||
{
|
||||
public TestLogger()
|
||||
: base(new Metadata() { CorrelationId = Guid.NewGuid() })
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
namespace Chatbot.Api.Application.Events
|
||||
{
|
||||
public class LoggerTested
|
||||
{
|
||||
}
|
||||
}
|
|
@ -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<IActionResult> CloseChat([FromBody] TestLogger closeChat)
|
||||
{
|
||||
var result = await _mediator.Send(closeChat);
|
||||
return Ok(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue