private void AddReceiver(Type type) { var info = new ReceiverInfo { Name = ReceiverUtils.GetTypeDescription(type), Type = type }; _receiverTypes.Add(type.FullName, info); }
private void StartUdp() { while ((_udpClient != null) && (_remoteEndPoint != null)) { try { byte[] buffer = _udpClient.Receive(ref _remoteEndPoint); string loggingEvent = this.EncodingObject.GetString(buffer); //Console.WriteLine(loggingEvent); // Console.WriteLine("Count: " + count++); if (Notifiable == null) { continue; } LogMessage logMsg = ReceiverUtils.ParseLog4JXmlLogEvent(loggingEvent, "UdpLogger"); if (_useRemoteIPAsNamespacePrefix) { logMsg.RootLoggerName = _remoteEndPoint.Address.ToString().Replace(".", "-"); logMsg.LoggerName = string.Format("{0}_{1}", _remoteEndPoint.Address.ToString().Replace(".", "-"), logMsg.LoggerName); } if (Notifiable != null) { Notifiable.Notify(logMsg); } } catch (ThreadAbortException ex) { Utils.log.Error("StartUdp " + ex.Message); Thread.ResetAbort(); break; } catch (Exception ex) { Utils.log.Error(ex.Message, ex); return; } } }
protected override void ProcessFileData() { int temp; while ((temp = fileReader.Read()) != -1) { // < ImmediateFlush value = "false" /> Óдí, ³¢ÊÔtcpreceiverµÄ·½·¨. sb.Append((char)temp); // This condition allows us to process events that spread over multiple lines if (IsEndWith(sb, log4jEndTag)) { LogMessage logMsg = ReceiverUtils.ParseLog4JXmlLogEvent(sb.ToString(), _fullLoggerName); // Notify the UI with the set of messages if (Notifiable != null) { Notifiable.Notify(logMsg); } sb = new StringBuilder(); } } }
void ProcessReceivedData(object newSocket) { try { using (var socket = (Socket)newSocket) using (var ns = new NetworkStream(socket, FileAccess.Read, false)) while (_socket != null) { using (StreamReader sr = new StreamReader(ns, this.EncodingObject)) { //NetworkStream may contain multiple log4j:event, if the tcp send message very frequently. StringBuilder sb = new StringBuilder(); int temp; while (_socket != null && (temp = sr.Read()) != -1) { sb.Append((char)temp); if (IsEndWith(sb, log4jEndTag)) { var str = sb.ToString(); LogMessage logMsg = ReceiverUtils.ParseLog4JXmlLogEvent(str, "TcpLogger"); logMsg.RootLoggerName = logMsg.LoggerName; //logMsg.LoggerName = string.Format(":{1}.{0}", logMsg.LoggerName, _port); if (_useRemoteIPAsNamespacePrefix) { var ipEndPoint = socket.RemoteEndPoint as IPEndPoint; if (ipEndPoint != null) { logMsg.LoggerName = string.Format("{0}.{1}", ipEndPoint.Address.ToString().Replace('.', '_'), logMsg.LoggerName); } else { var dnsEndPoint = socket.RemoteEndPoint as DnsEndPoint; if (dnsEndPoint != null) { logMsg.LoggerName = string.Format("{0}.{1}", dnsEndPoint.Host.Replace('.', '_'), logMsg.LoggerName); } else { // rmove ':' , because same app may have different port number after it restart. var fullAddress = socket.RemoteEndPoint.ToString(); var address = fullAddress.Substring(0, fullAddress.IndexOf(":")); logMsg.LoggerName = string.Format("{0}.{1}", address.Replace('.', '_'), logMsg.LoggerName); } } } if (Notifiable != null) { Notifiable.Notify(logMsg); } sb = new StringBuilder(); } } } } } catch (IOException ex) { Utils.log.Error("ProcessReceivedData " + ex.Message); } catch (Exception ex) { Utils.log.Error(ex.Message, ex); } }