Guides for Serilog and EFCore (#2134)
* Add serilog guide * added suggestions from Rozen * Add efcore guide * Fix review changes * Fix grammatical errors & review points
This commit is contained in:
36
docs/guides/other_libs/samples/ConfiguringSerilog.cs
Normal file
36
docs/guides/other_libs/samples/ConfiguringSerilog.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using Discord;
|
||||
using Serilog;
|
||||
using Serilog.Events;
|
||||
|
||||
public class Program
|
||||
{
|
||||
static void Main(string[] args) => new Program().MainAsync().GetAwaiter().GetResult();
|
||||
|
||||
public async Task MainAsync()
|
||||
{
|
||||
Log.Logger = new LoggerConfiguration()
|
||||
.MinimumLevel.Verbose()
|
||||
.Enrich.FromLogContext()
|
||||
.WriteTo.Console()
|
||||
.CreateLogger();
|
||||
|
||||
_client = new DiscordSocketClient();
|
||||
|
||||
_client.Log += LogAsync;
|
||||
|
||||
// You can assign your bot token to a string, and pass that in to connect.
|
||||
// This is, however, insecure, particularly if you plan to have your code hosted in a public repository.
|
||||
var token = "token";
|
||||
|
||||
// Some alternative options would be to keep your token in an Environment Variable or a standalone file.
|
||||
// var token = Environment.GetEnvironmentVariable("NameOfYourEnvironmentVariable");
|
||||
// var token = File.ReadAllText("token.txt");
|
||||
// var token = JsonConvert.DeserializeObject<AConfigurationClass>(File.ReadAllText("config.json")).Token;
|
||||
|
||||
await _client.LoginAsync(TokenType.Bot, token);
|
||||
await _client.StartAsync();
|
||||
|
||||
// Block this task until the program is closed.
|
||||
await Task.Delay(Timeout.Infinite);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user