Best place to store static error strings

那年仲夏 提交于 2019-12-10 09:48:05

问题


I was wondering if anyone had any input on the best practice of where to store static error strings in a C# application. I have a visual studio 2010 solution that has 5 projects and have defined several constant error messages to be returned via a WCF REST web service in the form of a message.

My current errors I have defined (hard-coded) are in the following format (CODE, MESSAGE):

999 - Your request could not be processed with the parameters specified.

I am not asking how to create custom classes derived from the Exception class because these errors are returned after corresponding Exceptions are raised to keep the AppPool from faulting.

Some ideas I was pondering storing the messages in: XML, Flat File, SQLite, and so on.

Does anyone have a preference and if so, why?

Thank you,

Jeffrey Kevin Pry


回答1:


I personally store these things in the projects Resources file, and then retrieve them when I need them. Doing it this way also makes it a lot easier to change them, for example if you needed the system to use another language all you'd do is switch the resources file for one in another language and voila!



来源:https://stackoverflow.com/questions/6370921/best-place-to-store-static-error-strings

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!