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.
- Host: GitHub
- URL: https://github.com/ffernandolima/log4netcore-sqlserver
- Owner: ffernandolima
- Created: 2019-08-27T14:32:12.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2024-01-16T20:01:27.000Z (over 2 years ago)
- Last Synced: 2025-04-30T22:15:31.506Z (about 1 year ago)
- Language: C#
- Homepage:
- Size: 28.3 KB
- Stars: 4
- Watchers: 1
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
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
[](https://www.nuget.org/packages/Log4NetCore.SqlServer/ "NuGet Version")
[](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.
