25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

TestLogger.cs 949 B

123456789101112131415161718192021222324252627282930313233343536
  1. using System;
  2. using System.Collections.Generic;
  3. using Microsoft.Extensions.Logging;
  4. namespace Cap.Consistency.Test
  5. {
  6. public interface ITestLogger
  7. {
  8. IList<string> LogMessages { get; }
  9. }
  10. public class TestLogger<TName> : ILogger<TName>, ITestLogger
  11. {
  12. public IList<string> LogMessages { get; } = new List<string>();
  13. public IDisposable BeginScope<TState>(TState state) {
  14. LogMessages.Add(state?.ToString());
  15. return null;
  16. }
  17. public bool IsEnabled(LogLevel logLevel) {
  18. return true;
  19. }
  20. public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func<TState, Exception, string> formatter) {
  21. if (formatter == null) {
  22. LogMessages.Add(state.ToString());
  23. }
  24. else {
  25. LogMessages.Add(formatter(state, exception));
  26. }
  27. }
  28. }
  29. }