LogEventArgs.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using System;
  2. namespace BepInEx.Logging
  3. {
  4. /// <summary>
  5. /// Log event arguments. Contains info about the log message.
  6. /// </summary>
  7. public class LogEventArgs : EventArgs
  8. {
  9. /// <summary>
  10. /// Logged data.
  11. /// </summary>
  12. public object Data { get; protected set; }
  13. /// <summary>
  14. /// Log levels for the data.
  15. /// </summary>
  16. public LogLevel Level { get; protected set; }
  17. /// <summary>
  18. /// Log source that emitted the log event.
  19. /// </summary>
  20. public ILogSource Source { get; protected set; }
  21. /// <summary>
  22. /// Creates the log event args-
  23. /// </summary>
  24. /// <param name="data">Logged data.</param>
  25. /// <param name="level">Log level of the data.</param>
  26. /// <param name="source">Log source that emits these args.</param>
  27. public LogEventArgs(object data, LogLevel level, ILogSource source)
  28. {
  29. Data = data;
  30. Level = level;
  31. Source = source;
  32. }
  33. /// <inheritdoc />
  34. public override string ToString()
  35. {
  36. return $"[{Level,-7}:{Source.SourceName,10}] {Data}";
  37. }
  38. /// <summary>
  39. /// Like <see cref="ToString"/> but appends newline at the end.
  40. /// </summary>
  41. /// <returns>Same output as <see cref="ToString"/> but with new line.</returns>
  42. public string ToStringLine()
  43. {
  44. return $"[{Level,-7}:{Source.SourceName,10}] {Data}{Environment.NewLine}";
  45. }
  46. }
  47. }