1+ #region Apache License
2+ //
3+ // Licensed to the Apache Software Foundation (ASF) under one or more
4+ // contributor license agreements. See the NOTICE file distributed with
5+ // this work for additional information regarding copyright ownership.
6+ // The ASF licenses this file to you under the Apache License, Version 2.0
7+ // (the "License"); you may not use this file except in compliance with
8+ // the License. You may obtain a copy of the License at
9+ //
10+ // http://www.apache.org/licenses/LICENSE-2.0
11+ //
12+ // Unless required by applicable law or agreed to in writing, software
13+ // distributed under the License is distributed on an "AS IS" BASIS,
14+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+ // See the License for the specific language governing permissions and
16+ // limitations under the License.
17+ //
18+ #endregion
19+
20+ using System . Text ;
21+ using log4net . Appender ;
22+ using log4net . Appender . Internal ;
23+ using log4net . Core ;
24+ using log4net . Layout ;
25+ using log4net . Tests . Appender . Internal ;
26+ using NUnit . Framework ;
27+
28+ namespace log4net . Tests . Appender ;
29+
30+ /// <summary>
31+ /// Tests for <see cref="RemoteSyslogAppender"/>
32+ /// </summary>
33+ [ TestFixture ]
34+ public sealed class RemoteSyslogAppenderTest
35+ {
36+ private sealed class RemoteAppender : RemoteSyslogAppender
37+ {
38+ /// <summary>
39+ /// Mock
40+ /// </summary>
41+ internal UdpMock Mock { get ; } = new ( ) ;
42+
43+ /// <inheritdoc/>
44+ protected override IUdpConnection CreateUdpConnection ( ) => Mock ;
45+ }
46+
47+ /// <summary>
48+ /// Simple Test for the <see cref="RemoteSyslogAppenderTest"/>
49+ /// </summary>
50+ /// <remarks>
51+ /// https://github.com/apache/logging-log4net/issues/255
52+ /// </remarks>
53+ [ Test ]
54+ public void RemoteSyslogTest ( )
55+ {
56+ System . Net . IPAddress ipAddress = new ( [ 127 , 0 , 0 , 1 ] ) ;
57+ RemoteAppender appender = new ( ) { RemoteAddress = ipAddress , Layout = new PatternLayout ( "%-5level - %message%newline" ) } ;
58+ appender . ActivateOptions ( ) ;
59+ LoggingEvent loggingEvent = new ( new ( )
60+ {
61+ Level = Level . Info ,
62+ Message = "Test message" ,
63+ LoggerName = "TestLogger" ,
64+ Domain = "TestDomain" ,
65+ } ) ;
66+ appender . DoAppend ( loggingEvent ) ;
67+ appender . Close ( ) ;
68+ Assert . That ( appender . Mock . ConnectedTo , Is . EqualTo ( ( 0 , ipAddress , 514 ) ) ) ;
69+ Assert . That ( appender . Mock . Sent , Has . Count . EqualTo ( 1 ) ) ;
70+ Assert . That ( appender . Mock . WasDisposed , Is . True ) ;
71+ Assert . That ( appender . Mock . Sent , Has . Count . EqualTo ( 1 ) ) ;
72+ const string expectedData = @"<14>TestDomain: INFO - Test message" ;
73+ Assert . That ( Encoding . ASCII . GetString ( appender . Mock . Sent [ 0 ] . Datagram ) , Is . EqualTo ( expectedData ) ) ;
74+ }
75+ }
0 commit comments