本文是小编为大家收集整理的关于存储静态错误字符串的最佳位置的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。
问题描述
我想知道是否有人对在C#应用程序中存储静态错误字符串的最佳实践有任何输入.我有一个Visual Studio 2010解决方案,该解决方案有5个项目,并以消息的形式通过WCF REST Web服务定义了几个恒定错误消息.
我定义(硬编码)的当前错误是以下格式(代码,消息):
999-无法使用指定的参数处理您的请求.
我不问如何创建从异常类派生的自定义类,因为在提出相应异常后返回这些错误以防止Apppool的故障.
我正在思考以下一些想法:xml,flat File,sqlite等.
有人有偏好吗?如果是,为什么?
谢谢,
Jeffrey Kevin Pry
推荐答案
我亲自将这些东西存储在项目中资源文件,然后在我需要时检索它们.这样做也可以使更改它们更容易,例如,如果您需要系统来使用另一种语言,您所要做的就是将资源文件切换为另一种语言的资源文件,瞧!
问题描述
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
推荐答案
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!