private FilePacketLogger GetLogFile(NetGraph graph) { FilePacketLogger logger = null; lock (_fileLogs) { if (_fileLogs.ContainsKey(graph.Uuid)) { logger = _fileLogs[graph.Uuid].Logger; } else { long currLogIndex = Interlocked.Increment(ref _currentLogIndex); string fileName = Path.Combine(redirectLogControl.BaseDirectory, String.Format("{0}-{1}", DateTime.Now.ToString("yyyyMMddHHmmss"), GeneralUtils.SanitizeFilename(graph.NetworkDescription, '_') + currLogIndex.ToString() + ".log")); try { FileRedirectLogEntry redirect = new FileRedirectLogEntry(graph.NetworkDescription, fileName); _fileLogs.Add(graph.Uuid, redirect); logger = redirect.Logger; } catch (IOException ex) { eventLogControl.Logger.LogException(ex); } } } return(logger); }
void _service_FilterLogPacketEvent(object sender, FilterPacketLogEventArgs e) { if (_enableRedirect) { if (redirectLogControl.Mode == RedirectLogControl.RedirectLogMode.ToFile) { FilePacketLogger logger = GetLogFile(e.Graph); if (logger != null) { logger.AddPacket(e.Packet); } } e.Filter = true; } }
public FileRedirectLogEntry(string name, string fileName) { Name = name; Logger = new FilePacketLogger(fileName); }