Exemplo n.º 1
0
 /// <summary>
 /// Creates an error model
 /// </summary>
 /// <param name="cId">Correlation ID</param>
 /// <param name="code">Error code</param>
 /// <param name="developerMessage">Developer message</param>
 /// <param name="userMessage">Friendly message</param>
 /// <param name="innerError">Inner error</param>
 /// <returns>An object of Error</returns>
 public static ErrorModel Create(Guid cId, ErrorCode code, string developerMessage, string userMessage, ErrorModel innerError = null)
 {
     return new ErrorModel
     {
         CorrelationId = cId,
         Code = code,
         DeveloperMessage = developerMessage,
         UserMessage = userMessage,
         InnerError = innerError
     };
 }
Exemplo n.º 2
0
        /// <summary>
        /// Builds a log-friendly string of the error object
        /// </summary>
        /// <param name="error">ErrorModel</param>
        /// <param name="builder">StringBuilder</param>
        /// <returns></returns>
        private StringBuilder BuildLogString(ErrorModel error, StringBuilder builder = null)
        {
            builder = builder ?? new StringBuilder();

            if (!string.IsNullOrEmpty(error.System))
            {
                builder.AppendFormat("System: {0}, ", error.System);
            }

            builder.AppendFormat("Code: {0}, ", error.Code);
            builder.AppendFormat("DeveloperMessage: {0}", error.DeveloperMessage);

            if (error.InnerError != null)
            {
                builder.Append(", InnerError: {");
                builder = BuildLogString(error.InnerError, builder);
                builder.Append("}");
            }

            return builder;
        }