You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/site/antora/modules/ROOT/pages/manual/appenders.adoc
+61Lines changed: 61 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -103,4 +103,65 @@ The RollingFileAppender can be configured to log to multiple files based upon da
103
103
|ForwardingAppender
104
104
|Can be used to wrap another appender, for example to attach additional filters.
105
105
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.
Copy file name to clipboardExpand all lines: src/site/antora/modules/ROOT/pages/manual/filters.adoc
+32-4Lines changed: 32 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -28,7 +28,7 @@ DENY:: The filter drops the log event.
28
28
NEUTRAL:: log4net behaves as if the filter was not present.
29
29
It is evaluated by the next filter in the filter chain.
30
30
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.
32
32
If the event gets to the end of the filter chain without being denied it is implicitly accepted and will be logged.
33
33
34
34
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
40
40
</filter>
41
41
----
42
42
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:
44
44
[source,xml]
45
45
----
46
46
<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
55
55
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.
56
56
This filter is only useful at the end of the filter chain.
57
57
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:
59
59
[source,xml]
60
60
----
61
61
<filter type="log4net.Filter.StringMatchFilter">
@@ -65,4 +65,32 @@ If we want to allow events that have either 'database' or 'ldap' in the message
65
65
<stringToMatch value="ldap"/>
66
66
</filter>
67
67
<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.
Copy file name to clipboardExpand all lines: src/site/antora/modules/ROOT/pages/manual/introduction.adoc
+33-14Lines changed: 33 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -298,22 +298,41 @@ In fundamental contradiction to biological parenthood, where parents always prec
298
298
299
299
In particular, a "parent" logger will find and link to its descendants even if it is instantiated after them.
300
300
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.
304
302
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.
307
305
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.
310
307
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
314
310
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[]
317
312
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.
0 commit comments