CapturingLogger.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536
  1. // Licensed to the .NET Foundation under one or more agreements.
  2. // The .NET Foundation licenses this file to you under the MIT license.
  3. using Microsoft.Build.Framework;
  4. namespace Microsoft.NET.Build.Containers.IntegrationTests;
  5. public class CapturingLogger : ILogger
  6. {
  7. public LoggerVerbosity Verbosity { get => LoggerVerbosity.Diagnostic; set { } }
  8. public string? Parameters { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
  9. private List<BuildMessageEventArgs> _messages = new();
  10. public IReadOnlyList<BuildMessageEventArgs> Messages { get { return _messages; } }
  11. private List<BuildWarningEventArgs> _warnings = new();
  12. public IReadOnlyList<BuildWarningEventArgs> Warnings { get { return _warnings; } }
  13. private List<BuildErrorEventArgs> _errors = new();
  14. public IReadOnlyList<BuildErrorEventArgs> Errors { get { return _errors; } }
  15. public List<string> AllMessages => Errors.Select(e => e.Message!).Concat(Warnings.Select(w => w.Message!)).Concat(Messages.Select(m => m.Message!)).ToList();
  16. public void Initialize(IEventSource eventSource)
  17. {
  18. eventSource.MessageRaised += (o, e) => _messages.Add(e);
  19. eventSource.WarningRaised += (o, e) => _warnings.Add(e);
  20. eventSource.ErrorRaised += (o, e) => _errors.Add(e);
  21. }
  22. public void Shutdown()
  23. {
  24. }
  25. }