An open API service indexing awesome lists of open source software.

https://github.com/ffernandolima/log4netcore-sqlserver

log4net AdoNetAppender for .NET Core.
https://github.com/ffernandolima/log4netcore-sqlserver

Last synced: about 1 year ago
JSON representation

log4net AdoNetAppender for .NET Core.

Awesome Lists containing this project

README

          

# Log4NetCore.SqlServer

log4net AdoNetAppender for .NET Core.

https://logging.apache.org/log4net/ has no support for AdoNetAppender yet, so this project solves this problem.

P.S: Only SQL Server database provider supported.

# Status
[![NuGet Version](https://img.shields.io/nuget/v/Log4NetCore.SqlServer.svg)](https://www.nuget.org/packages/Log4NetCore.SqlServer/ "NuGet Version")
[![NuGet Downloads](https://img.shields.io/nuget/dt/Log4NetCore.SqlServer.svg)](https://www.nuget.org/packages/Log4NetCore.SqlServer/ "NuGet Downloads")

# Getting Started

- Appender configuration

In your log4net.config, please add these configurations:

```XML





































```

Please pay attention to the property named "type", it shall use the qualified assembly "Log4NetCore.SqlServer.Appenders.AdoNetAppender, Log4NetCore.SqlServer".

Also, you need to provide your connection string name and the file which contains it through the properties "connectionStringName" and "connectionStringFile", so this app will find your connection string automatically.

- Set database connection manually (through code)

Some extensions were created in order to help you with it:

```C#

// Configure log4net
var assembly = [YOUR REPOSITORY ASSEMBLY];

XmlConfigurator.Configure(
LogManager.GetRepository(assembly),
new FileInfo($@"{AppDomain.CurrentDomain.BaseDirectory}log4net.config")
);

// Configure IConfiguration
var configuration = new ConfigurationBuilder()
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.Build();

// Get ConnectionString
var connectionString = configuration.GetConnectionString("log4netCoreDb");

// Configure Log4NetCore.SqlServer
int affectedAdoNetAppenders = 0;

// All repositories
var results = AdoNetAppenderHelper.SetConnectionString(connectionString);

// Specific repository from the provided assembly
affectedAdoNetAppenders = AdoNetAppenderHelper.SetConnectionString(assembly, connectionString);

// Specific repository
var loggerRepository = LogManager.GetRepository(assembly);

affectedAdoNetAppenders = loggerRepository.SetConnectionString(connectionString);

// Specific appender
var adoNetAppender = new AdoNetAppender();

adoNetAppender.SetConnectionString(connectionString);

```

# Support / Contributing
If you want to help with the project, feel free to open pull requests and submit issues.

# Donate

If you would like to show your support for this project, then please feel free to buy me a coffee.

Buy Me A Coffee