/// <summary> /// Initializes a new instance of the <see cref="Log"/> class /// with the specified log name. /// </summary> /// <param name="logName">Name of log. The log name will be used as the <see cref="Path"/>.</param> /// <exception cref="ArgumentNullException"/> public Log(string logName) { if (logName == null) throw new ArgumentNullException(logName); Name = logName; Path = !logName.EndsWith(".log") == true ? logName + ".log" : logName; LogBuilder = new LogBuilder(); }
/// <summary> /// Initializes a new instance of the <see cref="Log"/> class /// with the specified log name. /// </summary> /// <param name="logName">Name of log. The log name will be used as the <see cref="Path"/>.</param> /// <exception cref="ArgumentNullException"/> public Log(string logName) { if (logName == null) { throw new ArgumentNullException(logName); } Name = logName; Path = !logName.EndsWith(".log") == true ? logName + ".log" : logName; LogBuilder = new LogBuilder(); }
/// <summary> /// Initializes a new instance of the <see cref="Log"/> class /// with the specified log name and path. /// </summary> /// <param name="logName">Name of log.</param> /// <param name="logPath">Path of log.</param> /// <exception cref="ArgumentNullException"/> public Log(string logName, string logPath) { if (logName == null) throw new ArgumentNullException(logName); if (logPath == null) throw new ArgumentNullException(logPath); Name = logName; Path = logPath; LogBuilder = new LogBuilder(); }
/// <summary> /// Initializes a new instance of the <see cref="Log"/> class /// with the specified log name and path. /// </summary> /// <param name="logName">Name of log.</param> /// <param name="logPath">Path of log.</param> /// <exception cref="ArgumentNullException"/> public Log(string logName, string logPath) { if (logName == null) { throw new ArgumentNullException(logName); } if (logPath == null) { throw new ArgumentNullException(logPath); } Name = logName; Path = logPath; LogBuilder = new LogBuilder(); }
/// <summary> /// Logs data with the specified parameters in this /// signature(Exception ex). /// </summary> /// <param name="parameters">The parameters needed to log the data.</param> public override void LogData(params object[] parameters) { if (!(parameters[0] is Exception)) { throw new ArgumentException("parameters[0] must be a type of an Exception."); } var ex = (Exception)parameters[0]; var exType = ex.GetType(); var blockName = exType.Name; LogBuilder.OpenBlock(blockName); LogBuilder.AppendObject(ex); LogBuilder.CloseBlock(); if (AutoSave) { Save(); } }
/// <summary> /// Logs data with the specified parameters in this /// order(IPacket packet, PacketDirection direction) /// </summary> /// <param name="parameters">The parameters needed to log the data.</param> public override void LogData(params object[] parameters) { if (!(parameters[0] is IPacket)) { throw new ArgumentException("parameters[0] must be a type of an IPacket."); } if (!(parameters[1] is PacketDirection)) { throw new ArgumentException("parameters[1] must be a type of a PacketDirection."); } var packet = (IPacket)parameters[0]; var direction = (PacketDirection)parameters[1]; var blockName = string.Empty; var prefix = direction == PacketDirection.Server ? "[CLIENT > SERVER]" : "[CLIENT < SERVER]"; var packetName = packet.GetType().Name; blockName = string.Format("{0} {1} 0x{2:X2} ({2})", prefix, FormatPacketName(packetName), packet.ID); if (packet is KeepAliveRequestPacket || packet is KeepAliveResponsePacket) { LogBuilder.EmptyBlock(blockName); } else { LogBuilder.OpenBlock(blockName); LogBuilder.AppendObject(packet); LogBuilder.CloseBlock(); } if (AutoSave) { Save(); // check if autosaving } }