Log4net远程追加器输出
我正在配置文件中使用remoteAppender,并将日志远程发送到另一台计算机。在使用tcp发送信息时,我发现remoteAppender也发送了大量随机符号和字符,而不是我想要的日志字符串。我怀疑remoteAppender发送的不是日志字符串,而是记录器本身。我在接收广播时使用的方法很简单,并且取自msdm网站。有人知道如何将收到的networkstream转换回字符串并避免所有奇怪的输出吗Log4net远程追加器输出,log4net,Log4net,我正在配置文件中使用remoteAppender,并将日志远程发送到另一台计算机。在使用tcp发送信息时,我发现remoteAppender也发送了大量随机符号和字符,而不是我想要的日志字符串。我怀疑remoteAppender发送的不是日志字符串,而是记录器本身。我在接收广播时使用的方法很简单,并且取自msdm网站。有人知道如何将收到的networkstream转换回字符串并避免所有奇怪的输出吗 public void StartListener() { try
public void StartListener()
{
try
{
// Set the TcpListener on port 13000.
Int32 port = 32100;
// TcpListener server = new TcpListener(port);
server = new TcpListener(IPAddress.Any, port);
// Start listening for client requests.
server.Start();
// Buffer for reading data
Byte[] bytes = new Byte[256];
String data = null;
// Enter the listening loop.
while (true)
{
Console.Write("Waiting for a connection... ");
// Perform a blocking call to accept requests.
// You could also user server.AcceptSocket() here.
TcpClient client = server.AcceptTcpClient();
Console.WriteLine("Connected!");
data = null;
// Get a stream object for reading and writing
NetworkStream stream = client.GetStream();
int i;
// Loop to receive all the data sent by the client.
while ((i = stream.Read(bytes, 0, bytes.Length)) != 0)
{
// Translate data bytes to a ASCII string.
data = System.Text.Encoding.UTF8.GetString(bytes, 0, i);
Console.WriteLine("Received: {0}", data);
// Process the data sent by the client.
data = data.ToUpper();
byte[] msg = System.Text.Encoding.ASCII.GetBytes(data);
// Send back a response.
stream.Write(msg, 0, msg.Length);
Console.WriteLine("Sent: {0}", data);
}
// Shutdown and end connection
client.Close();
}
}
catch (SocketException e)
{
Console.WriteLine("SocketException: {0}", e);
}
catch (Exception e)
{
Console.WriteLine("Connection was terminated");
}
finally
{
// Stop listening for new clients.
server.Stop();
}
Console.WriteLine("\nHit enter to continue...");
Console.Read();
}
以下是通过remoteAppender向我发送日志时得到的输出:
Waiting for a 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☺♥ ♠
RemotingAppender使用.NET remoting将日志事件代理到实现log4net.Appender.RemotingAppender+IRemoteLoggingSink接口的端点。看起来您正试图通过TCP简单地读取呈现的日志消息,这是“有效的”,但正如您所指出的,您的数据流不包含呈现的日志字符串,而是包含远程二进制日志事件 试试TelnetAppender或UDPAppender;这些附加器在通过网络发送日志消息之前呈现日志消息,因此您将获得所需的字符串 看 及