TPJ.Logging 4.0.0

dotnet add package TPJ.Logging --version 4.0.0
NuGet\Install-Package TPJ.Logging -Version 4.0.0
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="TPJ.Logging" Version="4.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add TPJ.Logging --version 4.0.0
#r "nuget: TPJ.Logging, 4.0.0"
#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 TPJ.Logging as a Cake Addin
#addin nuget:?package=TPJ.Logging&version=4.0.0

// Install TPJ.Logging as a Cake Tool
#tool nuget:?package=TPJ.Logging&version=4.0.0

TPJ.Logging

Simple error logging library that can send emails and/or log to a txt file

Setup

appsettings.json

ApplicationName � (Required) Name of the application used on the log file names and e-mails

ErrorLogType (Required) - There are three types of error log types:

  1. Email - Errors are sent via e-mail only (as per rest of the config settings)
  2. LogFile - Errors are logged in a txt file (named � [{Environment}] {Application Name} Error Log.txt)
  3. EmailLogFile - Does both Email and LogFile

LogFileDirectory (Required for log file logging) - The location at which the log / error file will be placed

To (Required for e-mail logging) - Error e-mails sent to; Can be a list split by ; E.G "Test@test.com;Test2@test.com"

From (Required for e-mail logging) - E-mails are sent from this account

SmtpClient (Required for e-mail logging) - SMTP server which e-mails will be sent from

SmtpUser - Send e-mail using the given user name and password

SmtpPassword - Send e-mail using the given user name and password

Port - Port to send from

EnableSSL - Enable SSL when sending the e-mail

Example

Within appsettings.json and add (add your own settings):

"TPJ": {
  "Logging": {
    "ApplicationName": "Test App",
    "LogType": "EmailLogFile",
    "LogFileDirectory": "C:\\Test",
    "Email": {
      "From": "test-app@test.com",
      "SmtpClient": "smtp.gmail.com",
      "SmtpUser": "abc",
      "SmtpPassword": "xyz",
      "EnableSSL": true,
      "Port": 587
    }
  }
}

Within appsettings.{environment}.json add:

"TPJ": {
  "Logging": {
    "Email": {
      "To": "example@test.com"
    }
  }
}

ConfigureServices

To add logging simply add TPJ logging to your DI:

services.AddTPJLogging();

Example Error Log

Check out the git repo code for example setup for a console app and API.

private readonly TPJ.Logging.ILogger _logger; 

public HomeController(TPJ.Logging.ILogger logger) 
{ 
    _logger = logger; 
} 

Then within an IActionResult you might have this

public IActionResult About(Divide divide) 
{ 
	try 
	{ 
		var divideByZero = divide.ValueOne / divide.ValueTwo;
		return View(); 
	} 
	catch (Exception e) 
	{ 
		_logger.Log(System.Reflection.MethodBase.GetCurrentMethod(), e, divide);
		return RedirectToAction(nameof(Error)); 
	} 
}

This will then log the error with the current method information, the exception details and the details of the object �divide� � it will log nested classes within objects.

GDPR Sensitive Data

Any data that is personal / sensitive such as e-mail, address, passwords should not be logged or sent over e-mail. To hide this information you add [Sensitive] data attriribute to the property that contains the sensitive information.

[Sensitive]
public string Password { get; set; }

This will then remove the data when logging and place ##Redacted## instead.

Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  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
4.0.0 286 1/28/2023
3.1.2 1,159 8/19/2017
3.1.1 996 8/16/2017
3.0.0 922 8/15/2017
2.5.1.1 905 8/14/2017
2.5.1 954 7/12/2017
2.5.0 1,107 3/21/2017
2.2.3 1,204 10/28/2016
2.1.1 1,223 8/26/2016
1.1.3 1,618 4/19/2016

2023 update! V4.0.0 now runs on .NET 7 see github for more details