ErrorLogger.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #region File Description
  2. //-----------------------------------------------------------------------------
  3. // ErrorLogger.cs
  4. //
  5. // Microsoft XNA Community Game Platform
  6. // Copyright (C) Microsoft Corporation. All rights reserved.
  7. //-----------------------------------------------------------------------------
  8. #endregion
  9. #region Using Statements
  10. using System.Collections.Generic;
  11. using Microsoft.Build.Framework;
  12. #endregion
  13. namespace WinFormsContentLoading
  14. {
  15. /// <summary>
  16. /// Custom implementation of the MSBuild ILogger interface records
  17. /// content build errors so we can later display them to the user.
  18. /// </summary>
  19. class ErrorLogger : ILogger
  20. {
  21. /// <summary>
  22. /// Initializes the custom logger, hooking the ErrorRaised notification event.
  23. /// </summary>
  24. public void Initialize(IEventSource eventSource)
  25. {
  26. if (eventSource != null)
  27. {
  28. eventSource.ErrorRaised += ErrorRaised;
  29. }
  30. }
  31. /// <summary>
  32. /// Shuts down the custom logger.
  33. /// </summary>
  34. public void Shutdown()
  35. {
  36. }
  37. /// <summary>
  38. /// Handles error notification events by storing the error message string.
  39. /// </summary>
  40. void ErrorRaised(object sender, BuildErrorEventArgs e)
  41. {
  42. errors.Add(e.Message);
  43. }
  44. /// <summary>
  45. /// Gets a list of all the errors that have been logged.
  46. /// </summary>
  47. public List<string> Errors
  48. {
  49. get { return errors; }
  50. }
  51. List<string> errors = new List<string>();
  52. #region ILogger Members
  53. /// <summary>
  54. /// Implement the ILogger.Parameters property.
  55. /// </summary>
  56. string ILogger.Parameters
  57. {
  58. get { return parameters; }
  59. set { parameters = value; }
  60. }
  61. string parameters;
  62. /// <summary>
  63. /// Implement the ILogger.Verbosity property.
  64. /// </summary>
  65. LoggerVerbosity ILogger.Verbosity
  66. {
  67. get { return verbosity; }
  68. set { verbosity = value; }
  69. }
  70. LoggerVerbosity verbosity = LoggerVerbosity.Normal;
  71. #endregion
  72. }
  73. }