Log4net remoteAppender output -
i using remoteappender inside of config file , sending logs remotely computer. while sending information using tcp worked, found remoteappender sending large chunk of random symbols , characters rather log string want. suspect being sent remoteappender not log string, rather logger itself. method used read in incoming broadcast simple , taken msdm website. know of way convert networkstream received string , avoiding strange outputs?
public void startlistener() { try { // set tcplistener on port 13000. int32 port = 32100; // tcplistener server = new tcplistener(port); server = new tcplistener(ipaddress.any, port); // start listening client requests. server.start(); // buffer reading data byte[] bytes = new byte[256]; string data = null; // enter listening loop. while (true) { console.write("waiting connection... "); // perform blocking call accept requests. // user server.acceptsocket() here. tcpclient client = server.accepttcpclient(); console.writeline("connected!"); data = null; // stream object reading , writing networkstream stream = client.getstream(); int i; // loop receive data sent client. while ((i = stream.read(bytes, 0, bytes.length)) != 0) { // translate data bytes ascii string. data = system.text.encoding.utf8.getstring(bytes, 0, i); console.writeline("received: {0}", data); // process data sent client. data = data.toupper(); byte[] msg = system.text.encoding.ascii.getbytes(data); // send response. stream.write(msg, 0, msg.length); console.writeline("sent: {0}", data); } // shutdown , end connection client.close(); } } catch (socketexception e) { console.writeline("socketexception: {0}", e); } catch (exception e) { console.writeline("connection terminated"); } { // stop listening new clients. server.stop(); } console.writeline("\nhit enter continue..."); console.read(); }
here output got when sent log via remoteappender:
waiting connection... connected! received: .net☺ /♥ ♦ ☺☺$ tcp://149.63.90.84:32100/loggingsink♠ ☺☺↑ appl ication/octet-stream sent: .net☺ /♥ ♦ ☺☺$ tcp://149.63.90.84:32100/loggingsink♠ ☺☺↑ applicat ion/octet-stream received: ☺ ????☺ §¶ ↕ logevents↕?☺log4net.appender.remotingapp ender+iremoteloggingsink, log4net, version=1.2.11.0, culture=neutral, publickeyt oken=669e0ddf0bb1aa2a►☺ ☺ ☻ ♀♥ klog4net, version=1.2.11.0, culture=neu tral, publickeytoken=669e0ddf0bb1 sent: ☺ ????☺ §¶ ↕ logevents↕?☺log4net.appender.remotingappender+ir emoteloggingsink, log4net, version=1.2.11.0, culture=neutral, publickeytoken=669 e0ddf0bb1aa2a►☺ ☺ ☻ ♀♥ klog4net, version=1.2.11.0, culture=neutral, pu blickeytoken=669e0ddf0bb1 received: aa2a☻ ☺ ☺ ♦↓log4net.core.loggingevent♥ ♦ ♣♦ ↓log4ne t.core.loggingevent♂ loggername♣levelmessage threadname timestamp♀locationinfusername☼exceptionstring !log4net.util.propertity☺♦☺☺ ☻☻☺♦☺☻↕log4net.core.level♥ sent: aa2a☻ ☺ ☺ ♦↓log4net.core.loggingevent♥ ♦ ♣♦ ↓log4net.core.l oggingevent♂ loggername♣levelmessage threadname timestamp♀locationinfusername☼exceptionstring !log4net.util.propertity☺♦☺☺ ☻☻☺♦☺☻↕log4net.core.level♥ received: iesdictionary♥ ♥ ♠♣ ►project2.program ♠ ♠ ♥hi0 ♦6384?:?? uf? ♠ ♠♂ ‼project2.vshost.exe ♣♠ ↕log4net.core.level♥ ♀m_levelvalue♂m_levelname↕m_leveldisplayname ♥ p◄☺ ♠♀ ♣error ♀ ♣ !log4net.util.propertiesdictionary☺ sent: iesdictionary♥ ♥ ♠♣ ►project2.program ♠ ♠ ♥hi0 ♦6384?:?? uf? ♠ ♠♂ ‼project2.vshost.exe ♣♠ ↕log4net.core.level♥ ♀m_levelvalue♂m_levelname↕m_leveldisplayname ♥ p◄☺ ♠♀ ♣error ♀ ♣ !log4net.util.propertiesdictionary☺ ♂kollik-d1sd♂net_x003a_hostname☺♥ ♠ ♂kollik-d1sd♂x003a_hostname☺♥ ♠
the remotingappender uses .net remoting proxy log events endpoint implement log4net.appender.remotingappender+iremoteloggingsink interface. looks you're trying read rendered log message via tcp, "working" except that, point out, data stream not contain rendered log strings remoted binary log events.
try telnetappender or udpappender instead; these appenders render log message before sending on network, you'll string expect.
see http://logging.apache.org/log4net/release/sdk/log4net.appender.telnetappender.html , http://maddemcode.com/net/secrets-of-log4net-telnetappender/
Comments
Post a Comment