chatbot/Chatbot.Api.Application/CommandHandlers/TestLoggerHandler.cs

35 lines
1010 B
C#
Raw Permalink Normal View History

2020-06-07 14:43:34 +03:00
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}";
}
}