Microsoft.Extensions.Logging.Console

using DSharpPlus;
using DSharpPlus.Commands;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging.Console;
//...
//...
public static CommandsConfiguration CommandsConfiguration
{
get => new CommandsConfiguration
{
ServiceProvider = new ServiceCollection().AddLogging(x => x.AddConsole()).BuildServiceProvider()

};
}
using DSharpPlus;
using DSharpPlus.Commands;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging.Console;
//...
//...
public static CommandsConfiguration CommandsConfiguration
{
get => new CommandsConfiguration
{
ServiceProvider = new ServiceCollection().AddLogging(x => x.AddConsole()).BuildServiceProvider()

};
}
I try to build a Discord bot. I follow the instructions here: https://dsharpplus.github.io/DSharpPlus/articles/migration/slashcommands_to_commands.html but I doesn't work (I added Microsoft.Extensions.Logging.Console).
3 Replies
Keswiik
Keswiik10mo ago
Define "doesn't work"? Show some code where you're using this logger
jcotton42
jcotton4210mo ago
For bots, I strongly recommend using the Worker Service template. dotnet new worker on the cli When setting up the command config, just give it the same service provider you use for everything else. In the worker service, have IServiceProvider injected, and put the bot startup code (ConnectAsync and all that) in the ExecuteAsync Or actually I guess you could ditch the worker, and start the bot in Program.cs
Levitating Soul
Levitating SoulOP10mo ago
It still gives CS1061 for AddConsole() after adding the NuGet package (Microsoft.Extensions.Logging.Console). I get use it from inside MyBot.Bot.Bot.RunAsync() I call the RunAsync() (command to start the bot) inslde Program.Main() Thanks for your suggestion.

Did you find this page helpful?