36 lines
		
	
	
		
			929 B
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			36 lines
		
	
	
		
			929 B
		
	
	
	
		
			C#
		
	
	
	
	
	
| using Microsoft.Extensions.Logging;
 | |
| using System;
 | |
| 
 | |
| namespace Adaptation._Tests.Shared.Log;
 | |
| 
 | |
| public class ConsoleLogger : ILogger
 | |
| {
 | |
| 
 | |
|     public int EventId { get; set; }
 | |
| 
 | |
|     private readonly string _Name;
 | |
|     private readonly LogLevel _LogLevel;
 | |
| 
 | |
|     public ConsoleLogger(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);
 | |
|             Console.WriteLine(message);
 | |
|         }
 | |
|     }
 | |
| 
 | |
| } |