UnhandledExceptionLogger 1.1.1
See the version list below for details.
dotnet add package UnhandledExceptionLogger --version 1.1.1
NuGet\Install-Package UnhandledExceptionLogger -Version 1.1.1
<PackageReference Include="UnhandledExceptionLogger" Version="1.1.1" />
paket add UnhandledExceptionLogger --version 1.1.1
#r "nuget: UnhandledExceptionLogger, 1.1.1"
// Install UnhandledExceptionLogger as a Cake Addin #addin nuget:?package=UnhandledExceptionLogger&version=1.1.1 // Install UnhandledExceptionLogger as a Cake Tool #tool nuget:?package=UnhandledExceptionLogger&version=1.1.1
UnhandledExceptionLogger
A simplistic logger that hooks up to unhandled exceptions and logs them to a specified CSV file.
Installation
To install ErrorLogger, simply add the NuGet package to your project.
Usage
To start using ErrorLogger, initialize the logger in your main method:
var logger = new Logger();
You can also specify the log file path, the duration of the log history to keep, and the maximum size of the log file in kilobytes (KB) by using the following code:
var logger = new Logger(filePath, historyDuration, maxLogSize_KB,logLevel,debugOutLevel);
The logger should then pick up eceptions automatically. Note there are some known issues when working with multiple threads/tasks/contexts to pick up the exceptions.
Furthermore you can log exceptions and messages manually (for example for debugging or to log handeled exceptions):
try
{
// Some code that may throw an exception...
int result = int.Parse("not a number");
}
catch (Exception ex)
{
logger.Log(ex, Severity.Critical);
}
logger.Log("Application Start", "The application started successfully.", Severity.Info);
Example
Here's an example of how you can use ErrorLogger in your project:
using ErrorLogger;
namespace MyProject
{
class Program
{
static void Main(string[] args)
{
// initialize logger
var logger = new Logger(
filePath: "C:\\logs\\error.csv",
historyDuration: TimeSpan.FromDays(30.0),
maxLogSize_KB: 1024
);
// unhandled exception occurs, application crashes but exception gets logged
throw new Exception("Test exception");
}
}
}
In the example above, the logger is initialized with the file path "C:\logs\error.csv", a history duration of 30 days, and a maximum log size of 1024 KB. The log file is roll over, old entries older than the specified duration are deleted. The same is true for the logfile size.
If no parameters are specified, the logger loggs to the application directory into a file errors.log
with infinite size.
Note that there can be issues in multithreaded applications for the logger to pick up the exceptions.
sample output
Date and Time | Severity | Exception Type | Description | Location |
---|---|---|---|---|
2/26/2023 21:57 | Critical | DataMisalignedException | data is incorrect! | at Program.<Main>$(String[] args) in C:\Users\julia\OneDrive\Projects\Libraries\ErrorLogger\TestingApplication\Program.cs:line 9 |
2/26/2023 21:58 | Critical | Exception | this is a test exeption! | at Program.<Main>$(String[] args) in C:\Users\julia\OneDrive\Projects\Libraries\ErrorLogger\TestingApplication\Program.cs:line 9 |
2/26/2023 21:58 | Critical | DataMisalignedException | the data is misaligned! | at Program.<Main>$(String[] args) in C:\Users\julia\OneDrive\Projects\Libraries\ErrorLogger\TestingApplication\Program.cs:line 9 |
License
ErrorLogger is released under the MIT-MODERN-VARIANT
license.
Product | Versions 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 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. |
-
net6.0
- QuickCsv.Net (>= 1.0.5)
-
net7.0
- QuickCsv.Net (>= 1.0.5)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
1.1.1
- updated csv library
1.1.0
- added functionality of loglevels
- updated naming to make more sense
- added capability to log a message