DDev.Tooling.LoggerExtensions.Email 1.0.6

dotnet add package DDev.Tooling.LoggerExtensions.Email --version 1.0.6
NuGet\Install-Package DDev.Tooling.LoggerExtensions.Email -Version 1.0.6
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="DDev.Tooling.LoggerExtensions.Email" Version="1.0.6" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add DDev.Tooling.LoggerExtensions.Email --version 1.0.6
#r "nuget: DDev.Tooling.LoggerExtensions.Email, 1.0.6"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install DDev.Tooling.LoggerExtensions.Email as a Cake Addin
#addin nuget:?package=DDev.Tooling.LoggerExtensions.Email&version=1.0.6

// Install DDev.Tooling.LoggerExtensions.Email as a Cake Tool
#tool nuget:?package=DDev.Tooling.LoggerExtensions.Email&version=1.0.6

DDev.Tooling.LoggerExtensions.Email

What is this package?

DDev.Tooling.LoggerExtensions.Email allows you to easily setup an ILogger in your service container which will then send log outputs to email accounts, depending on their LogLevel defined within AppSettings.json.

Each email is formatted with colours depending on the LogLevel and titled accordingly. If an exception exists in the Log then this will also be output to the email, along with the Message, EventId, Application Name and Logger Category.

How do I use this package?

  1. Install the package using Nuget into your project.

  2. Within your 'Program.cs' add a using statement to include 'DDev.Tooling.LoggerExtensions.Email'

/Program.cs

using DDev.Tooling.LoggerExtensions.Email;
  1. Add the EmailLogger as a new logging provider.
/Program.cs

var builder = WebApplication.CreateBuilder(args);
builder.Logging.ClearProviders();
builder.Logging.AddEmailLogger();
  1. Edit AppSettings.json to include your configuration.
/AppSettings.json

{
  "Logging": {
    "EmailLogger": {
      "LogLevels": [
        "Warning",
        "Critical"
      ],
      "SendAs": "Alerts@domain.net",
      "Hostname": "mx1.domain.net",
      "Username": "Username",
      "Password": "Password",
      "UseTLS": true,
      "Port": 25,
      "AlertRecipients": [
        "Recipient1@domain.net",
        "Recipient2@domain.net"
      ],
      "UseConsoleLogging": false
    }
  }
}

Special Considerations

The Email Logger will react based upon the following logic.

if (Hostname is not defined) => Send Email using the recipients' MX record.
else if (Hostname is defined) {
    if (Username and Password is not defined) => Send Email without any authentication.
    else => Send email with 'AUTH LOGIN' basic authentication.
}

Logging and debugging.

When 'UseConsoleLogging' is set to 'true' within the AppSettings.json file, the logger will log the exception messages to the console window with 'Console.WriteLine()' allowing you to debug why an email will not send.


Tips

If you find any tools within here helpful, consider buying me a beer - I'd appreciate it.

Use PayPal to buy me a beer.

Change Log
1.0.0 → Initial Publish
1.0.1 → Resolved Typo's, Added Markdown README's
1.0.2 → Updated Email Template (This will change), removed the reliance on 'ARSoft.Tools.Net'
1.0.3 → Updated Email as colours were not being automatically changed.
1.0.4 → Email updated once more, previous email did not display in Outlook nicely.
1.0.5 → Re-read code, cleaned up and ensured no errors. Final version unless there are bugs.
1.0.6 → Fixed but where every time you'd have an exception, unable to connect to MX records.
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.6 586 6/23/2022
1.0.5 571 6/22/2022
1.0.4 577 6/22/2022
1.0.3 567 6/21/2022
1.0.2 570 6/21/2022
1.0.1 588 6/20/2022
1.0.0 592 6/20/2022