Skip to content

Commit 8432e4e

Browse files
committed
added remaining part of introduction
1 parent 0929509 commit 8432e4e

File tree

3 files changed

+126
-18
lines changed

3 files changed

+126
-18
lines changed

src/site/antora/modules/ROOT/pages/manual/appenders.adoc

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,65 @@ The RollingFileAppender can be configured to log to multiple files based upon da
103103
|ForwardingAppender
104104
|Can be used to wrap another appender, for example to attach additional filters.
105105
106+
|===
107+
108+
[#appender-additivity]
109+
== Appender Additivity
110+
111+
A logger can have multiple appenders.
112+
113+
Each enabled logging request is passed to all appenders attached to that logger, and also to appenders higher in the logger hierarchy.
114+
This behavior is called *appender additivity* and is enabled by default.
115+
116+
For example, if a console appender is attached to the root logger, all enabled logs will at least print to the console.
117+
If a file appender is added to logger `X`, logs from `X` and its children will go to both the file and the console.
118+
119+
Additivity can be disabled by setting a logger’s `additivity` flag to `false`.
120+
This prevents logging events from being passed to ancestor appenders beyond that point.
121+
122+
[NOTE]
123+
====
124+
If the `Animals` logger has `additivity = false`, then the `Animals.Carnivora` logger will only send its log messages to its own appenders and to `Animals`’ appenders—
125+
but not to any appenders higher up in the hierarchy, such as those on the root logger.
126+
====
127+
128+
[cols="Logger Name,Added Appender,Additivity Flag,Output Targets,Comment"]
129+
|===
130+
|Logger Name |Added Appenders |Additivity Flag |Output Targets |Comment
131+
132+
|root
133+
|ConsoleAppender
134+
|not applicable
135+
|ConsoleAppender
136+
|Default appender at the root.
137+
138+
|Animals
139+
|FileAppender, RollingFileAppender
140+
|true
141+
|ConsoleAppender, FileAppender, RollingFileAppender
142+
|Appenders of "Animals" and root.
143+
144+
|Animals.Carnivora
145+
|none
146+
|true
147+
|ConsoleAppender, FileAppender, RollingFileAppender
148+
|Inherited from "Animals" and root.
149+
150+
|Animals.Carnivora.Felidae
151+
|SmtpAppender
152+
|true
153+
|ConsoleAppender, FileAppender, RollingFileAppender, SmtpAppender
154+
|Appenders in "Animals.Carnivora.Felidae", "Animals", and root.
155+
156+
|Security
157+
|UdpAppender
158+
|false
159+
|UdpAppender
160+
|No appender accumulation because additivity is set to false.
161+
162+
|Security.Access
163+
|none
164+
|true
165+
|UdpAppender
166+
|Only appenders of "Security" are used due to disabled additivity in "Security".
106167
|===

src/site/antora/modules/ROOT/pages/manual/filters.adoc

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ DENY:: The filter drops the log event.
2828
NEUTRAL:: log4net behaves as if the filter was not present.
2929
It is evaluated by the next filter in the filter chain.
3030
31-
Any filter along the way can accept the event and stop processing, deny the event and stop processing, or allow the event on to the next filter.
31+
Any filter along the way can accept the event and stop processing, deny the event and stop processing, or allow the event on to the next filter.
3232
If the event gets to the end of the filter chain without being denied it is implicitly accepted and will be logged.
3333
3434
This filter will deny events that have a level that is lower than INFO or higher than FATAL. All events between INFO and FATAL will be logged.
@@ -40,7 +40,7 @@ This filter will deny events that have a level that is lower than INFO or higher
4040
</filter>
4141
----
4242
43-
If we want to only allow messages through that have a specific substring (e.g. 'database') then we need to specify the following filters:
43+
If we want to only allow messages through that have a specific substring (e.g. 'database') then we need to specify the following filters:
4444
[source,xml]
4545
----
4646
<filter type="log4net.Filter.StringMatchFilter">
@@ -55,7 +55,7 @@ If there is no next filter the event would be implicitly accepted and would be l
5555
But because we don't want the non matching events to be logged we need to use a log4net.Filter.DenyAllFilter that will just deny all events that reach it.
5656
This filter is only useful at the end of the filter chain.
5757
58-
If we want to allow events that have either 'database' or 'ldap' in the message text we can use the following filters:
58+
If we want to allow events that have either 'database' or 'ldap' in the message text we can use the following filters:
5959
[source,xml]
6060
----
6161
<filter type="log4net.Filter.StringMatchFilter">
@@ -65,4 +65,32 @@ If we want to allow events that have either 'database' or 'ldap' in the message
6565
<stringToMatch value="ldap"/>
6666
</filter>
6767
<filter type="log4net.Filter.DenyAllFilter" />
68-
----
68+
----
69+
70+
[#list-of-filters]
71+
== List of Filters
72+
73+
The following filters are defined in the log4net package:
74+
75+
[cols="Type,Description"]
76+
|===
77+
|Type |Description
78+
79+
|log4net.Filter.DenyAllFilter
80+
|Drops all logging events unconditionally.
81+
82+
|log4net.Filter.LevelMatchFilter
83+
|Allows only events with an exact level match.
84+
85+
|log4net.Filter.LevelRangeFilter
86+
|Allows events within a specified range of levels.
87+
88+
|log4net.Filter.LoggerMatchFilter
89+
|Matches events from loggers with names starting with a given string.
90+
91+
|log4net.Filter.PropertyFilter
92+
|Matches events based on a specific property's value.
93+
94+
|log4net.Filter.StringMatchFilter
95+
|Matches events containing a specific substring in the message.
96+
|===

src/site/antora/modules/ROOT/pages/manual/introduction.adoc

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -298,22 +298,41 @@ In fundamental contradiction to biological parenthood, where parents always prec
298298
299299
In particular, a "parent" logger will find and link to its descendants even if it is instantiated after them.
300300
301-
Configuration of the log4net environment is typically done at application initialization.
302-
The preferred way is by reading a configuration file.
303-
This approach will be discussed shortly.
301+
Logger configuration is usually done during application startup, typically via a configuration file.
304302
305-
Log4net makes it easy to name loggers by software component.
306-
This can be accomplished by statically instantiating a logger in each class, with the logger name equal to the fully qualified name of the class.
303+
Loggers are often named after the class they’re used in, using the fully qualified class name.
304+
This makes log output easy to trace and aligns naturally with the application's design.
307305
308-
This is a useful and straightforward method of defining loggers.
309-
As the log output bears the name of the generating logger, this naming strategy makes it easy to identify the origin of a log message.
306+
While other naming strategies are possible, this approach is simple, effective, and widely adopted.
310307
311-
However, this is only one possible, albeit common, strategy for naming loggers.
312-
Log4net does not restrict the possible set of loggers.
313-
The developer is free to name the loggers as desired.
308+
[#appenders]
309+
== Appenders
314310
315-
Nevertheless, naming loggers after the class where they are located seems to be the best strategy known so far.
316-
It is simple and obvious to the developers where each log message came from.
311+
See xref:./appenders.adoc[]
317312
318-
Most importantly, it leverages the design of the application to produce the design of the logger hierarchy.
319-
Hopefully, some thought has gone into the design of the application.
313+
[#filters]
314+
== Filters
315+
316+
See xref:./filters.adoc[]
317+
318+
[#layouts]
319+
== Layouts
320+
321+
See xref:./layouts.adoc[]
322+
323+
[#renderers]
324+
== Object Renderers
325+
326+
log4net can render the content of log messages using custom logic defined by the user.
327+
328+
For example, if you often log `Orange` objects, you can register an `OrangeRenderer` to format them consistently in logs.
329+
330+
Renderers follow the class hierarchy.
331+
If you register a `FruitRenderer`, it will be used for all `Fruit` types—including `Orange`—unless a more specific `OrangeRenderer` is also registered.
332+
333+
Renderers must implement the `log4net.ObjectRenderer.IObjectRenderer` interface.
334+
335+
[NOTE]
336+
====
337+
Format methods like `DebugFormat`, `InfoFormat`, etc., do *not* use Object Renderers.
338+
====

0 commit comments

Comments
 (0)