Exemple #1
0
        /// <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();
            }
        }
Exemple #2
0
        /// <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
            }
        }