Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Mikael Axel Kleinwort 154 posts 499 karma points c-trib
    Dec 09, 2024 @ 12:40
    Mikael Axel Kleinwort
    0

    Adding another logger to Umbraco (V13)

    I am trying to add another logger to Umbraco (Serilog Email Sink), however, I am unsure where to add the logger in Startup.cs. I am on Umbraco V13.

    I know how to create the new LoggerConfiguration, but what I don't knwo is what to do with it then :-)

    I try to do it in code, rather than in appsettings.json, since this way, it is easier to pull in secret credential information from other places.

    Any hint appreciated :-) ! Kind regards, Mikael

  • Farshad 8 posts 78 karma points
    Dec 20, 2024 @ 06:46
    Farshad
    0

    I got this part from ChatGPT, but I haven't tried it yet. They mentioned two methods. Please check if it doesn't work, and let me know. I will verify it.

    var builder = WebApplication.CreateBuilder(args);
    
    Log.Logger = new LoggerConfiguration()
    .WriteTo.Email(new EmailConnectionInfo
    {
        FromEmail = "[email protected]",
        ToEmail = "[email protected]",
        MailServer = "smtp.your-email-server.com",
        NetworkCredentials = new NetworkCredential("[email protected]", "your-password"),
        EmailSubject = "Log Email",
        Port = 587, // SMTP port
        EnableSsl = true
    })
    .CreateLogger();
    
    builder.Logging.ClearProviders(); builder.Logging.AddSerilog();var app = builder.Build();
    
  • Farshad 8 posts 78 karma points
    Dec 20, 2024 @ 06:48
    Farshad
    0

    another approach will be using appsettings.

     {"Serilog": {
    "Using": ["Serilog.Sinks.Email"],
    "WriteTo": [
      {
        "Name": "Email",
        "Args": {
          "FromEmail": "[email protected]",
          "ToEmail": "[email protected]",
          "MailServer": "smtp.your-email-server.com",
          "NetworkCredentials": {
            "UserName": "[email protected]",
            "Password": "your-password"
          },
          "EmailSubject": "Log Email",
          "Port": 587,
          "EnableSsl": true
        }
      }
    ]}} 
    
    builder.Host.UseSerilog((context, services, configuration) =>{
    configuration.ReadFrom.Configuration(context.Configuration);});
    
Please Sign in or register to post replies

Write your reply to:

Draft