/// <summary> /// 接受消息 /// </summary> private void ReceiveMessage() { while (IsContinueToListenToUDP) { try { byte[] buffer = _udpClient.Receive(ref _remoteEndPoint); if (Notifiable == null) { continue; } //获取LogMessage LogMessage logMsg = ParserHelper.ParseLayout(buffer, LogLayoutType); //检查等级过滤 if (!string.IsNullOrWhiteSpace(LevelFilterStr) && !LevelFilterStr.Contains(logMsg.Level)) { //需要过滤,且配置中不包含该等级名称 continue; } //保存日志到数据库 Notifiable.Notify(logMsg); } catch (Exception ex) { Console.WriteLine(ex); } } }
void Start(object newSocket) { try { using (var socket = (Socket)newSocket) using (var ns = new NetworkStream(socket, FileAccess.Read, false)) while (_socket != null) { var logMsg = ReceiverUtils.ParseLog4JXmlLogEvent(ns, "TcpLogger"); logMsg.RootLoggerName = logMsg.LoggerName; logMsg.LoggerName = string.Format(":{1}.{0}", logMsg.LoggerName, _port); if (Notifiable != null) { Notifiable.Notify(logMsg); } } } catch (IOException) { } catch (Exception e) { Console.WriteLine(e); } }
private void DebugMonitor_OnOutputDebugString(int pid, string text) { // Trim ending newline (if any) if (text.EndsWith(Environment.NewLine)) { text = text.Substring(0, text.Length - Environment.NewLine.Length); } // Replace dots by "middle dots" to preserve Logger namespace var processName = GetProcessName(pid); processName = processName.Replace('.', '·'); var logMsg = new LogMessage { Message = text, LoggerName = processName }; logMsg.LoggerName = $"{processName}.{pid}"; logMsg.Level = LogLevels.Instance[LogLevel.Debug]; logMsg.ThreadName = pid.ToString(); logMsg.TimeStamp = DateTime.Now; Notifiable.Notify(logMsg); }
protected override void ProcessFileData() { int temp; Parser parser = new Parser(); while ((temp = fileReader.Read()) != -1) { var log = parser.parse((char)temp); if (log != null) { if (Notifiable != null) { Notifiable.Notify(log); } } } var logLast = parser.GetLog(); if (logLast != null) { if (Notifiable != null) { Notifiable.Notify(logLast); } } }
private void Start() { while (_udpClient != null && _remoteEndPoint != null) { try { var buffer = _udpClient.Receive(ref _remoteEndPoint); var loggingEvent = Encoding.UTF8.GetString(buffer); if (Notifiable == null) { continue; } var logMsg = ReceiverUtils.ParseLog4JXmlLogEvent(loggingEvent, "UdpLogger"); logMsg.RootLoggerName = _remoteEndPoint.Address.ToString().Replace(".", "-"); logMsg.LoggerName = $"{_remoteEndPoint.Address.ToString().Replace(".", "-")}_{logMsg.LoggerName}"; Notifiable.Notify(logMsg); } catch (Exception ex) { Console.WriteLine(ex); return; } } }
private void EventLogOnEntryWritten(object sender, EntryWrittenEventArgs entryWrittenEventArgs) { LogMessage logMsg = new LogMessage(); logMsg.RootLoggerName = _baseLoggerName; logMsg.LoggerName = String.IsNullOrEmpty(entryWrittenEventArgs.Entry.Source) ? _baseLoggerName : String.Format("{0}.{1}", _baseLoggerName, entryWrittenEventArgs.Entry.Source); logMsg.Message = entryWrittenEventArgs.Entry.Message; logMsg.TimeStamp = entryWrittenEventArgs.Entry.TimeGenerated; logMsg.Level = LogUtils.GetLogLevelInfo(GetLogLevel(entryWrittenEventArgs.Entry.EntryType)); logMsg.ThreadName = entryWrittenEventArgs.Entry.InstanceId.ToString(); if (!String.IsNullOrEmpty(entryWrittenEventArgs.Entry.Category)) { logMsg.Properties.Add("Category", entryWrittenEventArgs.Entry.Category); } if (!String.IsNullOrEmpty(entryWrittenEventArgs.Entry.UserName)) { logMsg.Properties.Add("User Name", entryWrittenEventArgs.Entry.UserName); } Notifiable.Notify(logMsg); }
private void EventLogOnEntryWritten(object sender, EntryWrittenEventArgs entryWrittenEventArgs) { var logMsg = new LogMessage { RootLoggerName = _baseLoggerName, LoggerName = string.IsNullOrEmpty(entryWrittenEventArgs.Entry.Source) ? _baseLoggerName : $"{_baseLoggerName}.{entryWrittenEventArgs.Entry.Source}", Message = entryWrittenEventArgs.Entry.Message, TimeStamp = entryWrittenEventArgs.Entry.TimeGenerated, Level = LogUtils.GetLogLevelInfo(GetLogLevel(entryWrittenEventArgs.Entry.EntryType)), ThreadName = entryWrittenEventArgs.Entry.InstanceId.ToString() }; if (!string.IsNullOrEmpty(entryWrittenEventArgs.Entry.Category)) { logMsg.Properties.Add("Category", entryWrittenEventArgs.Entry.Category); } if (!string.IsNullOrEmpty(entryWrittenEventArgs.Entry.UserName)) { logMsg.Properties.Add("User Name", entryWrittenEventArgs.Entry.UserName); } Notifiable.Notify(logMsg); }
private void ReadFile() { if ((_fileReader == null)) { return; } if (_fileReader.BaseStream.Position > _fileReader.BaseStream.Length) { _fileReader.BaseStream.Seek(0, SeekOrigin.Begin); _fileReader.DiscardBufferedData(); } // Get last added lines var logMsgs = new List <LogMessage>(); List <string> fields; while ((fields = ReadLogEntry()) != null) { var logMsg = new LogMessage { ThreadName = string.Empty }; if (fields.Count == FieldList.Length) { ParseFields(ref logMsg, fields); logMsgs.Add(logMsg); } } // Notify the UI with the set of messages Notifiable.Notify(logMsgs.ToArray()); }
private void Start() { while ((_udpClient != null) && (_remoteEndPoint != null)) { try { byte[] buffer = _udpClient.Receive(ref _remoteEndPoint); string loggingEvent = Encoding.UTF8.GetString(buffer); //Console.WriteLine(loggingEvent); // Console.WriteLine("Count: " + count++); if (Notifiable == null) { continue; } LogMessage logMsg = ReceiverUtils.ParseLog4JXmlLogEvent(loggingEvent, "UdpLogger"); logMsg.RootLoggerName = _remoteEndPoint.Address.ToString().Replace(".", "-"); logMsg.LoggerName = string.Format("{0}_{1}", _remoteEndPoint.Address.ToString().Replace(".", "-"), logMsg.LoggerName); Notifiable.Notify(logMsg); } catch (Exception ex) { Console.WriteLine(ex); return; } } }
private void ParseEventLogEntry(EventLog eventLog, EventLogEntry entry) { LogMessage logMsg = new LogMessage(); var baseName = "EventLog." + eventLog.Log; if (AppendHostNameToLogger) { baseName = "EventLog_" + (this.MachineName == "." ? "local" : this.MachineName) + "." + eventLog.Log; } logMsg.RootLoggerName = baseName; logMsg.LoggerName = String.IsNullOrEmpty(entry.Source) ? baseName : String.Format("{0}.{1}", baseName, entry.Source); logMsg.Message = entry.Message; logMsg.TimeStamp = entry.TimeGenerated; logMsg.Level = LogUtils.GetLogLevelInfo(GetLogLevel(entry.EntryType)); logMsg.ThreadName = entry.InstanceId.ToString(); if (!String.IsNullOrEmpty(entry.Category)) { logMsg.Properties.Add("Category", entry.Category); } if (!String.IsNullOrEmpty(entry.UserName)) { logMsg.Properties.Add("User Name", entry.UserName); } if (Notifiable != null) { Notifiable.Notify(logMsg); } }
/// <summary> /// /// </summary> private void Start() { _queue = new MessageQueue(QueueName); _queue.ReceiveCompleted += delegate(Object source, ReceiveCompletedEventArgs asyncResult) { try { // End the asynchronous receive operation. Message m = ((MessageQueue)source).EndReceive(asyncResult.AsyncResult); if (Notifiable != null) { string loggingEvent = Encoding.ASCII.GetString(((MemoryStream)m.BodyStream).ToArray()); LogMessage logMsg = ReceiverUtils.ParseLog4JXmlLogEvent(loggingEvent, "MSMQLogger"); logMsg.LoggerName = string.Format("{0}_{1}", QueueName.TrimStart('.'), logMsg.LoggerName); logMsg.RootLoggerName = QueueName; Notifiable.Notify(logMsg); } if (BulkProcessBackedUpMessages) { Message[] all = ((MessageQueue)source).GetAllMessages(); if (all.Length > 0) { int numberofmessages = all.Length > 1000 ? 1000 : all.Length; LogMessage[] logs = new LogMessage[numberofmessages]; for (int i = 0; i < numberofmessages; i++) { Message thisone = ((MessageQueue)source).Receive(); string loggingEvent = Encoding.ASCII.GetString(((MemoryStream)thisone.BodyStream).ToArray()); LogMessage logMsg = ReceiverUtils.ParseLog4JXmlLogEvent(loggingEvent, "MSMQLogger"); logMsg.LoggerName = string.Format("{0}_{1}", QueueName.TrimStart('.'), logMsg.LoggerName); logs[i] = logMsg; } Notifiable.Notify(logs); } } ((MessageQueue)source).BeginReceive(); } catch (MessageQueueException) { // Handle sources of MessageQueueException. } }; _queue.BeginReceive(); }
private void NotifyWebSocketStateChange(WebSocketState state) { var logMsg = ReceiverUtils.ParseLog4JXmlLogEvent($"WebSocket state changed: {state}", "wssLogger"); logMsg.Level = LogLevels.Instance[LogLevel.Info]; var loggerName = WebSocketServerUri.Replace("wss://", "wss-").Replace(":", "-").Replace(".", "-"); logMsg.RootLoggerName = loggerName; logMsg.LoggerName = $"{loggerName}_{logMsg.LoggerName}"; Notifiable.Notify(logMsg); }
public async Task <IActionResult> Post(IFormFile file) { if (file == null) { await _notifiable.Notify("file", "Arquivo Inválido."); return(ResponseBadRequest()); } var fileInfo = new FileInfo(file.FileName); if (fileInfo.Extension != ".geojson") { await _notifiable.Notify("file", "O formato do arquivo esta inválido. [Formato Aceito: '.geojson']"); return(ResponseBadRequest()); } var size = file.Length; if (file.Length > 0) { using StreamReader sr = new StreamReader(file.OpenReadStream()); string geoJson = await sr.ReadToEndAsync(); var reader = new GeoJsonReader(); var featureCollection = reader.Read <FeatureCollection>(geoJson); var commandReponse = await _mediatorHandler.SendCommand(new SalvarGeoJsonCommand(file.FileName, size, featureCollection)); return(Response(new UploadGeoJsonModel(commandReponse.Id, file.FileName, size, commandReponse.Geometrias.Count(), MD5Hash(geoJson) ))); } return(ResponseBadRequest()); }
private void ReadFile() { if ((_fileReader == null) || (_fileReader.BaseStream.Length == _lastFileLength)) { return; } // Seek to the last file length _fileReader.BaseStream.Seek(_lastFileLength, SeekOrigin.Begin); // Get last added lines string line; var sb = new StringBuilder(); List <LogMessage> logMsgs = new List <LogMessage>(); while ((line = _fileReader.ReadLine()) != null) { if (_fileFormat == FileFormatEnums.Flat) { LogMessage logMsg = new LogMessage(); logMsg.RootLoggerName = _loggerName; logMsg.LoggerName = _fullLoggerName; logMsg.ThreadName = "NA"; logMsg.Message = line; logMsg.TimeStamp = DateTime.Now; logMsg.Level = LogLevels.Instance[LogLevel.Info]; logMsgs.Add(logMsg); } else { sb.Append(line); // This condition allows us to process events that spread over multiple lines if (line.Contains("</log4j:event>")) { LogMessage logMsg = ReceiverUtils.ParseLog4JXmlLogEvent(sb.ToString(), _fullLoggerName); logMsgs.Add(logMsg); sb = new StringBuilder(); } } } // Notify the UI with the set of messages Notifiable.Notify(logMsgs.ToArray()); // Update the last file length _lastFileLength = _fileReader.BaseStream.Position; }
public void LogEvents(LoggingEvent[] events) { if ((events == null) || (events.Length == 0) || (Notifiable == null)) { return; } LogMessage[] logMsgs = new LogMessage[events.Length]; for (int i = 0; i < events.Length; i++) { logMsgs[i] = CreateLogMessage(events[i]); } Notifiable.Notify(logMsgs); }
public void LogEvents(LoggingEvent[] events) { if (events == null || events.Length == 0 || Notifiable == null) { return; } var logMsgs = new LogMessage[events.Length]; for (var i = 0; i < events.Length; i++) { logMsgs[i] = CreateLogMessage(events[i]); } Notifiable.Notify(logMsgs); }
private void UpdateAvailableDevices <T>(ICollection <T> availableDevices, IReadOnlyCollection <T> existingDevices, Notifiable <T> deviceAdded, Notifiable <T> deviceDeleted) where T : IDeviceInfo { var devicesToRemove = availableDevices.Where(x => !existingDevices.Any(y => y.Name == x.Name)).ToList(); foreach (var deviceToRemove in devicesToRemove) { availableDevices.Remove(deviceToRemove); deviceDeleted.Notify(deviceToRemove); } var devicesToAdd = existingDevices.Where(x => !availableDevices.Any(y => y.Name == x.Name)).ToList(); foreach (var deviceToAdd in devicesToAdd) { availableDevices.Add(deviceToAdd); deviceAdded.Notify(deviceToAdd); } }
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(); } } }
private void OnBufferReceived(Task <WebSocketReceiveResult> obj) { if (obj.IsCompleted) { var loggingEvent = Encoding.UTF8.GetString(_buffer); _messageBuilder.Append(loggingEvent); Console.WriteLine(loggingEvent); if (obj.Result.EndOfMessage) { var logMsg = ReceiverUtils.ParseLog4JXmlLogEvent(loggingEvent, "wssLogger"); logMsg.Level = LogLevels.Instance[LogLevel.Debug]; var loggerName = WebSocketServerUri.Replace("wss://", "wss-").Replace(":", "-").Replace(".", "-"); logMsg.RootLoggerName = loggerName; logMsg.LoggerName = $"{loggerName}_{logMsg.LoggerName}"; Notifiable.Notify(logMsg); _messageBuilder.Clear(); } } }
private void HandleRawMessageFound(RawMessage rawMessage) { var message = messageUnpacker.Unpack(rawMessage); messageReceived.Notify(message); }
protected void NotifyException(Exception e) { exceptionCaught.Notify(e); }
private void HandleDeviceAdded(IDeviceInfo device) { availableDevices.Add(device); deviceAdded.Notify(device); }
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); } }