Example #1
0
        /// <summary>
        /// Complete logging a request
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="obj"></param>
        public static void CompleteRequest <T>(T obj, StringBuilder sb, ICustomLogger logger)
        {
            sb.AppendLine();

            //get return type data to put in the log
            sb.AppendLine($"Returned value of type {typeof(T).FullName}: {CustomLogger.GetArgsData(new object[] { obj })}");

            //perform normal logging here
            logger.Log(sb.ToString());
        }
Example #2
0
        /// <summary>
        /// Logs the object being sent in the request
        /// </summary>
        /// <typeparam name="TRequest"></typeparam>
        /// <param name="func"></param>
        /// <param name="sb"></param>
        public static void PerformRequestLogging <TRequest>(Func <TRequest> func, StringBuilder sb, ICustomLogger logger) where TRequest : class
        {
            var target = func.Target;

            if (target != null)
            {
                sb.AppendLine($"Requested value of type {typeof(TRequest).FullName}: ");

                foreach (var field in target.GetType().GetFields())
                {
                    sb.AppendLine($"Name: {field.Name}");
                    sb.AppendLine($"Value: {CustomLogger.GetArgsData(new object[] { field.GetValue(target) }, true)}");
                }

                logger.Log(sb.ToString());
            }
        }