ManualLogSource.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. using System;
  2. namespace BepInEx.Logging
  3. {
  4. /// <summary>
  5. /// A generic, multi-purpose log source. Exposes simple API to manually emit logs.
  6. /// </summary>
  7. public class ManualLogSource : ILogSource
  8. {
  9. /// <inheritdoc />
  10. public string SourceName { get; }
  11. /// <inheritdoc />
  12. public event EventHandler<LogEventArgs> LogEvent;
  13. /// <summary>
  14. /// Creates a manual log source.
  15. /// </summary>
  16. /// <param name="sourceName">Name of the log source.</param>
  17. public ManualLogSource(string sourceName)
  18. {
  19. SourceName = sourceName;
  20. }
  21. /// <summary>
  22. /// Logs a message with the specified log level.
  23. /// </summary>
  24. /// <param name="level">Log levels to attach to the message. Multiple can be used with bitwise ORing.</param>
  25. /// <param name="data">Data to log.</param>
  26. public void Log(LogLevel level, object data)
  27. {
  28. LogEvent?.Invoke(this, new LogEventArgs(data, level, this));
  29. }
  30. /// <summary>
  31. /// Logs a message with <see cref="LogLevel.Fatal"/> level.
  32. /// </summary>
  33. /// <param name="data">Data to log.</param>
  34. public void LogFatal(object data) => Log(LogLevel.Fatal, data);
  35. /// <summary>
  36. /// Logs a message with <see cref="LogLevel.Error"/> level.
  37. /// </summary>
  38. /// <param name="data">Data to log.</param>
  39. public void LogError(object data) => Log(LogLevel.Error, data);
  40. /// <summary>
  41. /// Logs a message with <see cref="LogLevel.Warning"/> level.
  42. /// </summary>
  43. /// <param name="data">Data to log.</param>
  44. public void LogWarning(object data) => Log(LogLevel.Warning, data);
  45. /// <summary>
  46. /// Logs a message with <see cref="LogLevel.Message"/> level.
  47. /// </summary>
  48. /// <param name="data">Data to log.</param>
  49. public void LogMessage(object data) => Log(LogLevel.Message, data);
  50. /// <summary>
  51. /// Logs a message with <see cref="LogLevel.Info"/> level.
  52. /// </summary>
  53. /// <param name="data">Data to log.</param>
  54. public void LogInfo(object data) => Log(LogLevel.Info, data);
  55. /// <summary>
  56. /// Logs a message with <see cref="LogLevel.Debug"/> level.
  57. /// </summary>
  58. /// <param name="data">Data to log.</param>
  59. public void LogDebug(object data) => Log(LogLevel.Debug, data);
  60. /// <inheritdoc />
  61. public void Dispose() { }
  62. }
  63. }