|
| 1 | +//// |
| 2 | + Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | + contributor license agreements. See the NOTICE file distributed with |
| 4 | + this work for additional information regarding copyright ownership. |
| 5 | + The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 | + (the "License"); you may not use this file except in compliance with |
| 7 | + the License. You may obtain a copy of the License at |
| 8 | + |
| 9 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + |
| 11 | + Unless required by applicable law or agreed to in writing, software |
| 12 | + distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + See the License for the specific language governing permissions and |
| 15 | + limitations under the License. |
| 16 | +//// |
| 17 | +
|
| 18 | +[#remotesyslogappender] |
| 19 | += RemoteSyslogAppender |
| 20 | +
|
| 21 | +The following example shows how to configure the `RemoteSyslogAppender` to send log messages to a remote syslog daemon. |
| 22 | +The syslog server listens on UDP port 514 by default. |
| 23 | +
|
| 24 | +The following example sends all events with Level WARN or higher to the remote server 192.168.1.100 on the default port with UTF8-Encoding. |
| 25 | +
|
| 26 | +[source,xml] |
| 27 | +---- |
| 28 | +<appender name="RemoteSyslogAppender" type="log4net.Appender.RemoteSyslogAppender"> |
| 29 | + <encoding>UTF-8</encoding> |
| 30 | + <layout type="log4net.Layout.PatternLayout"> |
| 31 | + <conversionPattern value="%date{MM/dd/yyyy HH:mm:ss.fff} [%thread] %-5level %logger - %message%newline" /> |
| 32 | + </layout> |
| 33 | + <remoteAddress value="192.168.1.100" /> |
| 34 | + <threshold value="WARN" /> |
| 35 | +</appender> |
| 36 | +---- |
| 37 | +
|
| 38 | +You can also specify: |
| 39 | +
|
| 40 | +* Facility (default: user) |
| 41 | +* Identity (default: application name) |
| 42 | +
|
| 43 | +[source,xml] |
| 44 | +---- |
| 45 | +<appender name="RemoteSyslogAppender" type="log4net.Appender.RemoteSyslogAppender"> |
| 46 | + <encoding>UTF-8</encoding> |
| 47 | + <facility>Alert</facility> |
| 48 | + <layout type="log4net.Layout.PatternLayout"> |
| 49 | + <conversionPattern value="%date{MM/dd/yyyy HH:mm:ss.fff} [%thread] %-5level %logger - %message%newline" /> |
| 50 | + </layout> |
| 51 | + <identity>MyApp-Canary</identity> |
| 52 | + <remoteAddress value="192.168.1.100" /> |
| 53 | + <threshold value="WARN" /> |
| 54 | +</appender> |
| 55 | +---- |
| 56 | +
|
| 57 | +If your log message contains multiple lines, it will be logged as multiple separate syslog entries instead of a single multiline message. |
| 58 | +
|
| 59 | +This might lead to confusion when analyzing logs because related lines could appear interleaved with logs from other sources. |
| 60 | +
|
| 61 | +Example: |
| 62 | +
|
| 63 | +[source,csharp] |
| 64 | +---- |
| 65 | +try |
| 66 | +{ |
| 67 | + throw new InvalidTimeZoneException(); |
| 68 | +} |
| 69 | +catch (InvalidTimeZoneException e) |
| 70 | +{ |
| 71 | + logger.Error(e, "setting daylight saving time failed") |
| 72 | +} |
| 73 | +---- |
| 74 | +
|
| 75 | +[source,log] |
| 76 | +---- |
| 77 | +12/21/2024 14:07:41.508 [main] ERROR log4net.Tests - setting daylight saving time failed |
| 78 | +Exception of type 'System.InvalidTimeZoneException' was thrown. |
| 79 | +12/21/2024 14:07:41.511 [worker] WARN log4net.Tests - some unrelated log message |
| 80 | + at log4net.Tests.Appender.RemoteSyslogAppenderTest.LineBreakTest() |
| 81 | + at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor) |
| 82 | + at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr) |
| 83 | +---- |
0 commit comments