36 lines
938 B
C#

using Microsoft.Extensions.Logging;
using System;
namespace Adaptation._Tests.Shared.Log;
public class DebugLogger : ILogger
{
public int EventId { get; set; }
private readonly string _Name;
private readonly LogLevel _LogLevel;
public DebugLogger(LogLevel logLevel, string name)
{
_Name = name;
EventId = 0;
_LogLevel = logLevel;
if (string.IsNullOrEmpty(_Name))
{ }
}
public IDisposable BeginScope<TState>(TState state) => null;
public bool IsEnabled(LogLevel logLevel) => logLevel >= _LogLevel;
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func<TState, Exception, string> formatter)
{
if (IsEnabled(logLevel) && (EventId == 0 || EventId == eventId.Id))
{
string message = formatter(state, null);
System.Diagnostics.Debug.Print(message);
}
}
}