Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NET 6 Not working #11

Open
norbertmarkiel opened this issue Dec 8, 2022 · 3 comments
Open

NET 6 Not working #11

norbertmarkiel opened this issue Dec 8, 2022 · 3 comments

Comments

@norbertmarkiel
Copy link

Hello.
I have a problem using this sink. After applying the following configuration

   Serilog.Log.Logger = new LoggerConfiguration().MinimumLevel.Verbose()
               .WriteTo.Discord(WebhookId, WebhookToken)
            //or async
            //.WriteTo.Async(a =>
            //a.Discord(WebhookId, WebhookToken))
            .WriteTo.Console(Serilog.Events.LogEventLevel.Verbose)
     .CreateLogger();

    Serilog.Log.Verbose("Test0");
    Serilog.Log.Information("Test1");
    Serilog.Log.Debug("Test2");
    Serilog.Log.Error("Test3");
    Serilog.Log.Fatal("Test4");

It receives logs to the console, but does not get them to the discord server via webhook.
I have added a webhook to the server, and from it I fetched ID and Token.
Additionally, I installed Serilog 2.12.0, DiscordNet.Webhook 2.6.1, and Serilog.Sink.Console 4.1.0
Can I ask for some hint?

@dhabierre
Copy link

No issue with .NET 7 / WebAPI

Serilog 2.12.0
Serilog.Sinks.File 5.0.0
Serilog.AspNetCore 6.1.0
Serilog.Sinks.Discord 1.2.1

Logging Registering

public static void RegisterLogging(this WebApplicationBuilder builder)
{
    builder.Logging.ClearProviders();
    builder.Logging.AddConsole();

    builder.Logging.AddSerilog(
        new LoggerConfiguration()
            .ReadFrom.Configuration(builder.Configuration)
            .Enrich.FromLogContext()
            .CreateLogger());
}

Setup Configuration

"Serilog": {
  "Using": [ "Serilog.Sinks.File", "Serilog.Sinks.Discord" ],
  "MinimumLevel": {
    "Default": "Information",
    "Override": {
      "Microsoft.EntityFrameworkCore.Database.Command": "Warning"
    }
  },
  "WriteTo": [
    {
      "Name": "File",
      "Args": {
        "path": "C:\\TEMP\\MY_APP_NAME.Api-.log",
        "rollingInterval": "Day",
        "outputTemplate": "[{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} {CorrelationId} {Level:u3}] {Username} {Message:lj}{NewLine}{Exception}"
      }
    },
    {
      "Name": "Discord",
      "Args": {
        "WebhookId": "105...",
        "WebhookToken": "DCH..."
      }
    }
  ]
}

Do not forget to create the #channel webhook

image

Hope this help.

@linmar22
Copy link

Hope this help.

It doesn't. Using async sink with inline configuration...

        Logger = new LoggerConfiguration()
            .WriteTo.Console()
            .WriteTo.File(logFile, rollingInterval: RollingInterval.Day, rollOnFileSizeLimit: true)
            .WriteTo.Async(x=>x.Discord(_config.Logging.DiscordWebhookId, _config.Logging.DiscordWebhookToken)).Enrich.FromLogContext()
            .CreateLogger();

Logs to console, file, but not Discord.

@norbertmarkiel
Copy link
Author

In the end, I used a Serilog.Sinks.Discord.Lite by Colombera Javier.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants