A collection of helper functions for the Microsoft.Extensions.Logging logging tool.
Build & Test Status (main) | |
Nuget Package Version | |
SonarCloudQuality Gate Status |
You can get the latest version of this software as a nuget package form nuget.org
Tool | Command/Code |
---|---|
Package Manager | PM> Install-Package jjm.one.Microsoft.Extensions.Logging.Helpers -Version X.Y.Z |
.NET CLI | > dotnet add package jjm.one.Microsoft.Extensions.Logging.Helpers --version X.Y.Z |
PackageReference | <PackageReference Include="jjm.one.Microsoft.Extensions.Logging.Helpers" Version="X.Y.Z" /> |
Package CLI | > paket add jjm.one.Microsoft.Extensions.Logging.Helpers --version X.Y.Z |
Script & Interactive | > #r "nuget: jjm.one.Microsoft.Extensions.Logging.Helpers, X.Y.Z" |
Cake as Addin | #addin nuget:?package=jjm.one.Microsoft.Extensions.Logging.Helpers&version=X.Y.Z |
Cake as Tool | #tool nuget:?package=jjm.one.Microsoft.Extensions.Logging.Helpers&version=X.Y.Z |
class MyClass {
// ...
void MyFancyFunction() {
// log the function call (minimal parameters)
logger.LogFctCall();
// log the function call (full parameters)
logger.LogFctCall(GetType(), MethodBase.GetCurrentMethod(), LogLevel.Debug);
try {
//...
}
catch (Exception exc) {
// Log the exception (minimal parameters)
logger.LogExcInFctCall(exc);
// Log the exception (full parameters)
logger.LogExcInFctCall(exc, GetType(), MethodBase.GetCurrentMethod(), "My custom exception message!", LogLevel.Error);
}
}
// ...
}
Function called: MyClass -> MyFancyFunction
Exception thrown in: MyClass -> MyFancyFunction
My custom exception message!
The full documentation for this package can be found here.
The associated repo for this package can be found here.