?
Solved

C# Error message formatting

Posted on 2014-09-11
3
Medium Priority
?
72 Views
Last Modified: 2016-06-21
we currently have a very convoluted methodology for displaying error messages.  But right now, I would just like to know how to correct one specific message.
The code used to build the message is:
        /// <summary>
        /// Adds the error details.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <param name="errors">The errors.</param>
        private void AddErrorDetails(ref string message, Dictionary<string, string> errors)
        {
            if (errors == null)
            {
                return;
            }

            if (message == null)
            {
                message = string.Empty;
            }

            foreach (string key in errors.Keys)
            {
                if (!string.IsNullOrEmpty(message))
                {
                    message += Environment.NewLine;
                }

                if (key != null)
                {
                    message += errors[key];
                }
            }
        }

Open in new window


the resulting message looks like:

error-msg.png
I would like it to be more like:

Delivery succeeded but with errors. See below for details.
Adjusting stock:  NrfiInd=N, ParentMals UIC = 09107,  Niin = 007345641, Location - Staging......

you get the idea.
Any help would be appreciated.
0
Comment
Question by:PSCTECH
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 36

Accepted Solution

by:
Miguel Oz earned 2000 total points
ID: 40318551
Just to clarify, your question is about:
a) How to remove the curly braces regardless of their location?
b) How to remove extra key entry? e.g.  ParentMals={ParentMals UIC = 09107} to  ParentMals UIC = 09107
c) Are the extra keys well known values? (e.g. we can create a list so that we can replace them accordingly)

For (a), you just need to replace the braces with a blank space as follows:
message.Replace("{", " ").Replace("}", " ");

Open in new window



If more help is needed please post errors[key] contents and answer to my questions.
0
 

Author Comment

by:PSCTECH
ID: 40319082
a. worked great, thank you.
b. yes that's how I want it to display
c.  no they are volatile and set at run time

I'm not at the office right now, I will try to get the errors[key] content as soon as I can
0

Featured Post

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question