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.

ConfiguringSerilog.cs 1.2 KiB

123456789101112131415161718192021222324252627282930313233343536
  1. using Discord;
  2. using Serilog;
  3. using Serilog.Events;
  4. public class Program
  5. {
  6. static void Main(string[] args) => new Program().MainAsync().GetAwaiter().GetResult();
  7. public async Task MainAsync()
  8. {
  9. Log.Logger = new LoggerConfiguration()
  10. .MinimumLevel.Verbose()
  11. .Enrich.FromLogContext()
  12. .WriteTo.Console()
  13. .CreateLogger();
  14. _client = new DiscordSocketClient();
  15. _client.Log += LogAsync;
  16. // You can assign your bot token to a string, and pass that in to connect.
  17. // This is, however, insecure, particularly if you plan to have your code hosted in a public repository.
  18. var token = "token";
  19. // Some alternative options would be to keep your token in an Environment Variable or a standalone file.
  20. // var token = Environment.GetEnvironmentVariable("NameOfYourEnvironmentVariable");
  21. // var token = File.ReadAllText("token.txt");
  22. // var token = JsonConvert.DeserializeObject<AConfigurationClass>(File.ReadAllText("config.json")).Token;
  23. await _client.LoginAsync(TokenType.Bot, token);
  24. await _client.StartAsync();
  25. // Block this task until the program is closed.
  26. await Task.Delay(Timeout.Infinite);
  27. }
  28. }