AspNetCore.Extensions.Logging 4.0.0

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

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

AspNetCore.Extensions.Logging

Use this package for logging all success, warning, error and exception messages. You can also log into mongodb database.

Configuration

appsettings.json

if you want to log into mongodb database, you should add the ConnectionParameters in your appsettings.json configuration file like this :

"ConnectionParameters": {
      "Default": {
        "Host": "your ip address",
        "Username": "your username",
        "Password": "your password",
        "DatabaseName": "database name",
        "Port": "27017" //or other port
     }
 }
Startup.cs

use this line to register all "HandleException" class attribute for all controllers and actions in the application, else you can call the annotation in the specific controller or action in your application code.

In Startup.cs, on ConfigureServices method add :

using AspNetCore.Extensions.Logging;
using AspNetCore.Extensions.Logging.Attributes;

services.AddControllers(options =>
{
	  //register all “HandleExceptionAttribute” class attribute for all controllers and actions
      options.Filters.Add(new HandleExceptionAttribute());
});

//Use Logging extension without mongodb database
services.AddLoggingExtension();

//Use Logging extension with mongodb database configuration
services.AddLoggingExtension(Configuration.GetConnectionParameters("Default"));

Utilisation

[HandleException(ExceptionHandled = true, LogStackTrace = true , SaveToDatabase = true)] //logging any exception in controller Home
public class HomeController : Controller

        private readonly IServiceLogging _logging;
        public HomeController(IServiceLogging logging)
        {
            _logging= logging;
        }
        [HandleException] //logging any exception in action Index
        public IActionResult Index()
        {
            //logging information in log file
            _logging.LogInformation("Hi i'm an info");
            
            //logging error message in log file
            _logging.LogError("Error message");
            
            //logging warning message in log file
            _logging.LogWarning("Warning message");
            
            //logging success message in log file
            _logging.LogSuccess("Success message");
            
			//logging information in mongodb database
			//log any object, ananymous object is also accepted 
            _logging.LogInformationToDatabase(new {Prop1 = Value1 , Prop2 = Value2 /*,......*/ });
            
            //logging information in mongodb database
            _logging.LogErrorToDatabase(new {Prop1 = Value1 , Prop2 = Value2 /*,......*/ });
            
            //logging warning message in mongodb database
            _logging.LogWarningToDatabase(new {Prop1 = Value1 , Prop2 = Value2 /*,......*/ });
            
            //logging success message in mongodb database
            _logging.LogSuccessToDatabase(new {Prop1 = Value1 , Prop2 = Value2 /*,......*/ });
            
            try
            {
                int b = 0;
                int x = 1/b;
            }
            catch(Exception e)
            {
                //logging exception in log file
	            _logging.LogException(e);
	            _logging.LogException(e, true); //logging with stacktrace :)
	            
				//logging exception in mongodb database
	            _logging.LogExceptionToDatabase(e);
	            
	            //logging with specific object
	            _logging.LogExceptionToDatabase(e , new {Prop1 = Value1 , Prop2 = Value2 /*,......*/});
	            
	            //logging with stacktrace and specific object
	            _logging.LogExceptionToDatabase(e,new {Prop1 = Value1 , Prop2 = Value2 /*,......*/}, true); 
            }
            
        }
}
Product 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. 
.NET Core netcoreapp3.1 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on AspNetCore.Extensions.Logging:

Package Downloads
CapitalSix.AspNetCore.Middleware.ErrorHandling

Middleware for generic error handling in AspNetCore.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
4.0.0 3,319 3/19/2020
3.0.0 548 2/13/2020
2.0.0 477 2/12/2020
1.0.0 575 2/12/2020