TPJ.Logging
3.1.1
See the version list below for details.
dotnet add package TPJ.Logging --version 3.1.1
NuGet\Install-Package TPJ.Logging -Version 3.1.1
<PackageReference Include="TPJ.Logging" Version="3.1.1" />
paket add TPJ.Logging --version 3.1.1
#r "nuget: TPJ.Logging, 3.1.1"
// Install TPJ.Logging as a Cake Addin #addin nuget:?package=TPJ.Logging&version=3.1.1 // Install TPJ.Logging as a Cake Tool #tool nuget:?package=TPJ.Logging&version=3.1.1
TPJ Logging library - Easily Log errors into a log file and/or e-mail. Simple, light weight, easy to setup!
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. 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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Microsoft.Extensions.Configuration (>= 2.0.0)
- Microsoft.Extensions.Options (>= 2.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
V3.0.0 only supports .netstandard2.0, which works in .net4.6.1 + / .netcore2.0 +. If you are using .net4.5.2 / .net 4.6 you can use TPJ.Logging V2.X.X.
ASP.Net Core Website / WebAPI Set up using both E-mail and Log file.
Within appsettings.json and add the following
{
"TPJ": {
"Logging": {
"ApplicationName": "",
"Error":{
"LogType": "",
"LogFileDirectory": "",
"Email":{
"To": "",
"From": "",
"SmtpClient": "",
"SmtpUser": "",
"SmtpPassword": "",
"Port": "",
"EnableSSL": ""
}
}
}
}
}
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 - (Not required) send e-mail using the given user name and password
SmtpPassword - (Not required) send e-mail using the given user name and password
Port - (Not required) port to send from
EnableSSL - (Not required) enable SSL when sending the e-mail
Example appsettings.json setup using Gmail to send error e-mails –
{
"TPJ": {
"Logging": {
"ApplicationName": "Test Application",
"Error":{
"LogType": "EmailLogFile",
"LogFileDirectory": "C:\Logging",
"Email":{
"To": "test@test.com",
"From": "test@gmail.com ",
"SmtpClient": "smtp.gmail.com",
"SmtpUser": "test@gmail.com",
"SmtpPassword": "testPassword",
"Port": "587",
"EnableSSL": "true"
}
}
}
}
}
Once appsettings.json is done open StartUp.cs file and go to ConfigureServices
services.AddSingleton< TPJ.Logging.IErrorLogger, TPJ.Logging.ErrorLogger>();
Then using DI within asp.net core you can call IErrorLogger like so
private readonly TPJ.Logging.IErrorLogger _logger;
public HomeController(TPJ.Logging.IErrorLogger 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.