WeihanLi.Common.Logging.Log4Net 1.0.48-preview-20211212-110315

Prefix Reserved
This is a prerelease version of WeihanLi.Common.Logging.Log4Net.
There is a newer version of this package available.
See the version list below for details.
dotnet add package WeihanLi.Common.Logging.Log4Net --version 1.0.48-preview-20211212-110315                
NuGet\Install-Package WeihanLi.Common.Logging.Log4Net -Version 1.0.48-preview-20211212-110315                
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="WeihanLi.Common.Logging.Log4Net" Version="1.0.48-preview-20211212-110315" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add WeihanLi.Common.Logging.Log4Net --version 1.0.48-preview-20211212-110315                
#r "nuget: WeihanLi.Common.Logging.Log4Net, 1.0.48-preview-20211212-110315"                
#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 WeihanLi.Common.Logging.Log4Net as a Cake Addin
#addin nuget:?package=WeihanLi.Common.Logging.Log4Net&version=1.0.48-preview-20211212-110315&prerelease

// Install WeihanLi.Common.Logging.Log4Net as a Cake Tool
#tool nuget:?package=WeihanLi.Common.Logging.Log4Net&version=1.0.48-preview-20211212-110315&prerelease                

WeihanLi.Common.Logging.Log4Net WeihanLi.Common.Logging.Log4Net

Intro

  • log4net extensions

    • log4net ElasticSearchAppender
    • Log4NetHelper
  • Log4NetLoggerProviderfor Microsoft.Extensions.Logging

  • Log4NetLogHelperProvider for WeihanLi.Common.Logging

Use log4net only

  1. log4net init

    Log4NetHelper.LogInit(); // log4net.config for default
    
    Log4NetHelper.LogInit(log4netConfigFilePath);
    
  2. GetLogger

    var genericLogger = Log4NetHelper.GetLogger<ClassName>();
    
    var typeLogger = Log4NetHelper.GetLogger(typeof(Program));
    
    var logger = Log4NetHelper.GetLogger("LoggerName");
    
  3. Log message

    logger.Debug(msg);
    logger.Info(msg);
    logger.Info(msg, exception);
    logger.Warn(msg);
    logger.Warn(msg, exception);
    logger.Error(msg);
    logger.Error(msg, exception);
    logger.Fatal(msg);
    logger.Fatal(msg, exception);
    
  4. log4net config sample

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
  </configSections>
  <log4net>
    <appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
      <file type="log4net.Util.PatternString" value="./Log/systemLog.%date{yyyy-MM-dd}.log" />
      <appendToFile value="true" />
      <encoding value="unicodeFFFE" />
      <rollingStyle value="Date" />
      <datePattern value="yyyyMMdd" />
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%date [%thread] %-5level %logger - %message%newline" />
      </layout>
    </appender>
    <appender name="AdoNetAppender" type="log4net.Appender.AdoNetAppender">
      <bufferSize value="100" />
      <connectionType value="System.Data.SqlClient.SqlConnection, System.Data" />
      <connectionString value="data source=.;initial catalog=WebLog;integrated security=false;persist security info=True;User ID=[***];Password=[***]" />
      <commandText value="INSERT INTO [dbo].[TestLog]([Date],[Thread],[Level],[Logger],[Message],[Exception]) VALUES(@log_date, @thread, @log_level, @logger, @message, @exception)" />
      <parameter>
        <parameterName value="@log_date" />
        <dbType value="DateTime" />
        <layout type="log4net.Layout.RawTimeStampLayout" />
      </parameter>
      <parameter>
        <parameterName value="@thread" />
        <dbType value="String" />
        <size value="255" />
        <layout type="log4net.Layout.PatternLayout">
          <conversionPattern value="%thread" />
        </layout>
      </parameter>
      <parameter>
        <parameterName value="@log_level" />
        <dbType value="String" />
        <size value="50" />
        <layout type="log4net.Layout.PatternLayout">
          <conversionPattern value="%level" />
        </layout>
      </parameter>
      <parameter>
        <parameterName value="@logger" />
        <dbType value="String" />
        <size value="255" />
        <layout type="log4net.Layout.PatternLayout">
          <conversionPattern value="%logger" />
        </layout>
      </parameter>
      <parameter>
        <parameterName value="@message" />
        <dbType value="String" />
        <size value="4000" />
        <layout type="log4net.Layout.PatternLayout">
          <conversionPattern value="%message" />
        </layout>
      </parameter>
      <parameter>
        <parameterName value="@exception" />
        <dbType value="String" />
        <size value="2000" />
        <layout type="log4net.Layout.ExceptionLayout" />
      </parameter>
      <filter type="log4net.Filter.LevelRangeFilter">
        
        <param name="LevelMin" value="WARN" />
      </filter>
    </appender>
    <appender name="TraceAppender" type="log4net.Appender.TraceAppender">
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
      </layout>
    </appender>
    <appender name="AspNetTraceAppender" type="log4net.Appender.AspNetTraceAppender">
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
      </layout>
    </appender>
    <appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender">
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%date [%thread] %-5level %logger - %message%newline" />
      </layout>
    </appender>
    <appender name="ColoredConsoleAppender" type="log4net.Appender.ColoredConsoleAppender">
      <mapping>
        <level value="ERROR" />
        <foreColor value="White" />
        <backColor value="Red, HighIntensity" />
      </mapping>
      <mapping>
        <level value="DEBUG" />
        <backColor value="Green" />
      </mapping>
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%date [%thread] %-5level %logger - %message%newline" />
      </layout>
    </appender>
    <appender name="SmtpAppender" type="log4net.Appender.SmtpAppender">
      <authentication value="Basic" />
      <username value="ben121011@126.com" />
      <password value="*******" />
      <to value="w***@outlook.com" />
      <from value="ben121011@126.com" />
      <subject value="logging message test" />
      <smtpHost value="smtp.126.com" />
      <bufferSize value="512" />
      
      <lossy value="true" />
      
      <filter type="log4net.Filter.LevelRangeFilter">
        <levelMin value="ERROR" />
        <levelMax value="FATAL" />
      </filter>
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%newline %date  %newline [%thread] %newline %-5level %logger  %newline - %message" />
      </layout>
    </appender>
    <appender name="ElasticSearchAppender" type="WeihanLi.Common.Logging.Log4Net.ElasticSearchAppender, WeihanLi.Common.Logging.Log4Net">
      <bufferSize value="2" />
      <ElasticSearchUrl value="http://localhost:9200" />
    </appender>
    <root>
      <level value="ALL" />
      <appender-ref ref="TraceAppender" />
      <appender-ref ref="ConsoleAppender" />
      <appender-ref ref="RollingLogFileAppender" />
      
    </root>
  </log4net>
</configuration>

use Log4NetLoggerProvider

ILoggerFactory loggerFactory = new LoggerFactory();
loggerFactory.AddLog4Net(); // loggerFactory.AddLog4Net(log4netConfigFilePath);

you can config in asp.net core use code like below in your Startup:

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            loggerFactory.AddLog4Net();

            // ...
        }

use Log4NetLogHelperProvider

LogHelper.AddLogProvider(new ILogHelperProvider[] {
                new WeihanLi.Common.Logging.Log4Net.Log4NetLogHelperProvider()
            });
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.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos 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.60-preview-20230728-022632 152 7/28/2023
1.0.60-preview-20230723-122007 145 7/23/2023
1.0.60-preview-20230715-064515 140 7/15/2023
1.0.59 1,015 3/14/2023
1.0.58 356 11/26/2022
1.0.57 384 11/20/2022
1.0.56 410 11/11/2022
1.0.56-preview-20221110-145231 159 11/10/2022
1.0.55 425 10/26/2022
1.0.54 472 10/12/2022
1.0.54-preview-20220927-012727 175 9/27/2022
1.0.53 542 7/17/2022
1.0.53-preview-20220709-025158 181 7/9/2022
1.0.53-preview-20220707-145349 168 7/7/2022
1.0.52 478 5/28/2022
1.0.51 511 4/9/2022
1.0.50 535 3/16/2022
1.0.49 452 3/13/2022
1.0.49-preview-20220312-180433 177 3/12/2022
1.0.49-preview-20220309-012617 175 3/9/2022
1.0.49-preview-20220306-151500 176 3/6/2022
1.0.48 365 1/8/2022
1.0.48-preview-20211220-105237 202 12/20/2021
1.0.48-preview-20211212-110315 193 12/12/2021
1.0.47 402 11/28/2021
1.0.47-preview-20211009-134935 233 10/9/2021
1.0.46 501 3/20/2021
1.0.46-preview-20210320-094828 289 3/20/2021
1.0.46-preview-20210320-090449 300 3/20/2021
1.0.46-preview-20210320-065305 337 3/20/2021
1.0.46-preview-20210313-212124 248 3/13/2021
1.0.45 432 2/28/2021
1.0.44 387 2/13/2021
1.0.44-preview-20210201-164451 244 2/1/2021
1.0.44-preview-20210131-152307 263 1/31/2021
1.0.44-preview-20210131-041429 242 1/31/2021
1.0.43 633 11/14/2020
1.0.43-preview-20201108-152412 391 11/8/2020
1.0.42 500 10/18/2020
1.0.42-preview-20200920-113000 382 9/20/2020
1.0.41 631 8/8/2020
1.0.41-preview-20200804-090048 329 8/4/2020
1.0.40 548 7/15/2020
1.0.40-preview-20200713-113453 345 7/13/2020
1.0.40-preview-20200625-063932 358 6/25/2020
1.0.39 566 6/13/2020
1.0.39-preview-20200610-070004 350 6/10/2020
1.0.39-preview-20200603-023614 387 6/3/2020
1.0.38 535 5/22/2020
1.0.38-preview-20200520-154642 365 5/20/2020
1.0.38-preview-20200519-171358 358 5/19/2020
1.0.37 562 5/17/2020
1.0.37-preview-20200517-083059 372 5/17/2020
1.0.37-preview-20200516-074403 358 5/16/2020
1.0.37-preview-20200514-094816 338 5/14/2020
1.0.37-preview-20200514-042225 337 5/14/2020
1.0.36 492 5/12/2020
1.0.36-preview-20200511-165228 350 5/11/2020
1.0.36-preview-20200511-151124 365 5/11/2020
1.0.36-preview-20200507-074046 353 5/7/2020
1.0.35 485 5/1/2020
1.0.35-preview-20200429-180449 399 4/29/2020
1.0.35-preview-20200426-133934 354 4/26/2020
1.0.35-preview-20200425-165753 346 4/25/2020
1.0.35-preview-20200425-035111 337 4/25/2020
1.0.34 527 4/19/2020
1.0.28 1,043 1/1/2020
1.0.27 609 12/31/2019
1.0.27-preview-20191230-051305 415 12/30/2019
1.0.26 680 11/28/2019
1.0.23.8 963 8/3/2019
1.0.23.8-preview-20190802-1... 407 8/2/2019
1.0.23.7 567 7/23/2019
1.0.22.6 768 7/16/2019
1.0.17 1,201 4/27/2019
1.0.13 880 3/14/2019