You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

logging.md 1.3 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. ---
  2. title: Logging
  3. ---
  4. Discord.Net's clients provide a [Log] event that all messages will be
  5. disbatched over.
  6. For more information about events in Discord.Net, see the [Events]
  7. section.
  8. [Log]: xref:Discord.Rest.BaseDiscordClient#Discord_Rest_BaseDiscordClient_Log
  9. [Events]: events.md
  10. ### Usage
  11. To receive log events, simply hook the discord client's log method
  12. to a Task with a single parameter of type [LogMessage]
  13. It is recommended that you use an established function instead of a
  14. lambda for handling logs, because most [addons] accept a reference
  15. to a logging function to write their own messages.
  16. ### Usage in Commands
  17. Discord.Net's [CommandService] also provides a log event, identical
  18. in signature to other log events.
  19. Data logged through this event is typically coupled with a
  20. [CommandException], where information about the command's context
  21. and error can be found and handled.
  22. #### Samples
  23. [!code-csharp[Logging Sample](samples/logging.cs)]
  24. #### Tips
  25. Due to the nature of Discord.Net's event system, all log event
  26. handlers will be executed synchronously on the gateway thread. If your
  27. log output will be dumped to a Web API (e.g. Sentry), you are advised
  28. to wrap your output in a `Task.Run` so the gateway thread does not
  29. become blocked while waiting for logging data to be written.