MNet.Log4NetExtensions 1.0.1

dotnet add package MNet.Log4NetExtensions --version 1.0.1
NuGet\Install-Package MNet.Log4NetExtensions -Version 1.0.1
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="MNet.Log4NetExtensions" Version="1.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add MNet.Log4NetExtensions --version 1.0.1
#r "nuget: MNet.Log4NetExtensions, 1.0.1"
#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 MNet.Log4NetExtensions as a Cake Addin
#addin nuget:?package=MNet.Log4NetExtensions&version=1.0.1

// Install MNet.Log4NetExtensions as a Cake Tool
#tool nuget:?package=MNet.Log4NetExtensions&version=1.0.1

MNet.Log4NetExtensions

This library is based on https://github.com/KentorIT/Log4NetExtensions library.

It has two extensions:

  1. Conversion Pattern: where every log send to log4net is converted into ONE line, so multiline logs (like exceptions...) are written in one line.
  2. Filter: where you can set some specific time frame and filter will forward log only if enough messages are received in that specific time frame.

Conversion Pattern

Usage is extremely easy. just add layout and instead of %message use %one_line_message

Example

  <layout type="MNet.Log4NetExtensions.OneLineMessagePatternLayout, MNet.Log4NetExtensions">
    <conversionPattern value="%date %level %logger - %one_line_message %newline" />
  </layout>

Filter

With this filter you can set some specific time frame and filter will forward log only if enough messages are received in that specific time frame.

This means that if you set time frame to 1 minute and buffer to 5 messages. Filter will pass 6th message, if it is received less than 1 minute after first message. After processing the message, buffer is cleared!

How is this useful?

When web apps are running at night, there can be some errors. If one user is having a problem in the middle of the night, I will not get up. But if there are 5 errors in 1 hour, then there is some kind of a problem and I will have to investigate it.

And that is the whole purpose of this filter. I setup file log which is logging all errors and SMS log which will fire only it 5 messages are received within 1 hour range.

<appender name="FileAppenderAll" type="log4net.Appender.FileAppender">
  <file value="app_all.log" />
  <appendToFile value="false" />
  <layout type="log4net.Layout.PatternLayout">
    <conversionPattern value="%date %level %logger - %message%newline" />
  </layout>
</appender>

<appender name="SMSAppender" type="log4net.Appender.SmtpAppender">
  <to value="xxx" />
  <from value="xxx" />
  <subject value="xxx" />
  <smtpHost value="xxx" />
  <layout type="log4net.Layout.PatternLayout">
    <conversionPattern value="%date %level %logger - %message%newline" />
  </layout>
  <filter type="MNet.Log4NetExtensions.TimeFilter, MNet.Log4NetExtensions">
    <TimeSpan value="01:00:00"/>
    <BufferSize value="5"/>
  </filter>
</appender>

Example

Filter is set as:

TimeSpan = 10 minutes

BufferSize = 3 messages

Time (min.) Message Current buffer Action Description
1 M1 M1 None First message in buffer
5 M2 M1, M2 None Second message in buffer
13 M3 M2, M3 None First message in out of the buffer because it is older than 10 minutes
14 M4 <empty> Fire There were 3 mesages (M2, M3, M4) in time span of 10 minutes so filter is activated, message M4 is written to log and buffer is cleared
20 M5 M5 None First message in buffer
22 M6 M5, M6 None Second message in buffer
35 M7 M7 None Messages M5 and M6 are too old so they are thrown out of the buffer

... and so on ...

nuget

You can download binaries from nuget: https://www.nuget.org/packages/MNet.Log4NetExtensions/

Product Compatible and additional computed target framework versions.
.NET Framework net45 is compatible.  net451 was computed.  net452 was computed.  net46 was computed.  net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 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.1 410 7/27/2021
1.0.0 1,033 1/18/2018