Net5Logger 1.0.0

dotnet add package Net5Logger --version 1.0.0
                    
NuGet\Install-Package Net5Logger -Version 1.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="Net5Logger" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Net5Logger" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Net5Logger" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Net5Logger --version 1.0.0
                    
#r "nuget: Net5Logger, 1.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.
#:package Net5Logger@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Net5Logger&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Net5Logger&version=1.0.0
                    
Install as a Cake Tool

Net 5 Logging ILogger Extension

Small Library to enable ILogger to Log into database or text file

To install nuget package run

    Install-Package Net5Logger -Version 1.0.0

In Program.cs add

using Net5Logger.DatabaseLogging;
using Net5Logger.FileLogging;

Extend host builder with

Host.CreateDefaultBuilder(args)
        .ConfigureLogging(x =>
        x.AddEventLog()
        .AddConsole()
        .AddDatabaseLogging("{YOUR-DB-CONNECTION-STRING}")
        .AddFileLogging(Directory.GetCurrentDirectory() + "/App_Data/")
        .AddFilter<DatabaseLoggerProvider>(logLevel => logLevel == LogLevel.Error)

If you want to log just specific type of errors you can set filtering for provider. Example for database provider to log only errors:

.AddFilter<DatabaseLoggerProvider>(logLevel => logLevel == LogLevel.Error)

Then use ILogger as usual and that's all.

If you want to log to database , create table in your database:

CREATE TABLE [dbo].[Logs](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[LogLevel] [nvarchar](max) NULL,
	[EventId] [nvarchar](max) NULL,
	[State] [nvarchar](max) NULL,
	[Exception] [nvarchar](max) NULL,
	[Message] [nvarchar](max) NULL,
	[ProccesTimeMiliSeconds] [nvarchar](max) NULL,
	[Host] [nvarchar](max) NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

Example for blazor (on index.razor:

Inject logger:

@using Microsoft.Extensions.Logging
@inject ILogger<Index> Logger

Set Button to call function:

<button @onclick="@TestLogger" class="btn btn-primary">Test Logger</button>

Set in code:

    @code{
 void TestLogger()
    {
        try
        {
            Logger.LogError("testing Warning");
            Logger.LogInformation("testing Information");
            Logger.LogWarning("testing warning");
            Logger.LogCritical("testing critical");
            throw new System.ArgumentException("Testing Catch for library", "testing catch exception");

        }
        catch (Exception ex)
        {
            Logger.LogError(ex, "testing catch exception");
        }

    }
}

Happy Coding!

Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  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.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.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
1.0.0 504 12/18/2020