Log4NetCore 1.0.0
dotnet add package Log4NetCore --version 1.0.0
NuGet\Install-Package Log4NetCore -Version 1.0.0
<PackageReference Include="Log4NetCore" Version="1.0.0" />
paket add Log4NetCore --version 1.0.0
#r "nuget: Log4NetCore, 1.0.0"
// Install Log4NetCore as a Cake Addin #addin nuget:?package=Log4NetCore&version=1.0.0 // Install Log4NetCore as a Cake Tool #tool nuget:?package=Log4NetCore&version=1.0.0
CrestApps.Log4NetCore
Setup
Add a file called "log4net.config" into the root of your project with the following context
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<log4net debug="false">
<appender name="LogFileAppender" type="log4net.Appender.RollingFileAppender,log4net">
<param name="File" value="app.log" />
<appendToFile value="true" />
<rollingStyle value="Size" />
<maxSizeRollBackups value="10" />
<maximumFileSize value="10MB" />
<staticLogFileName value="true" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger - %message %newline %location %newline %newline %newline" />
</layout>
</appender>
<root>
<level value="ERROR" />
<appender-ref ref="LogFileAppender" />
</root>
</log4net>
<system.diagnostics>
<trace autoflush="true">
<listeners>
<add name="textWriterTraceListener" type="System.Diagnostics.TextWriterTraceListener" initializeData="log4net.txt" />
</listeners>
</trace>
</system.diagnostics>
</configuration>
Then in Program.cs file or Global.cs you can register your log4net as provider like os
ILoggerProvider logProvider = new Log4NetProvider(StorageHelper.MakePath("log4net.config"));
services.AddLogging((builder) =>
{
builder.ClearProviders();
builder.AddProvider(logProvider).AddFilter(level => level >= LogLevel.Information);
});
Then you can register an instance of you ILogger like this
ILogger logger = logProvider.CreateLogger("MyAppName");
services.AddSingleton(logger);
Finally, anywhere you want to log into, inject ILogger
into your class and use it.
Disclaimer: Most of code in this package was copied from https://rajujoseph.com/log4net-provider-for-net-core/ This package make it easy for you to include Log4Net into your code project without having to manually add code into your project
Product | Versions 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 | netcoreapp2.2 is compatible. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
-
.NETCoreApp 2.2
- log4net (>= 2.0.8)
- Microsoft.Extensions.Logging (>= 2.2.0)
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 | 3,170 | 2/17/2019 |