我目前正在通过log
阻止exception error
System.InvalidOPerationException
try{}... catch{}
类型Log.txt
Microsoft Visual Studio dialog box
的文本文件。我担心的是System.InvalidOPerationException
输出:
消息:类型' System.Exception'的异常扔了。
StackTrace:
日期:2016/4/21 9:50:42
理想情况下,我希望对try....catch
所揭示的异常的性质有点提供更多信息。举例说明:
发生
try { // call method } catch (InvalidOperationException exc) { using (StreamWriter writer = new StreamWriter(logPath, true)) { writer.WriteLine("Message :" + exc.Message + "<br/>" + Environment.NewLine + "StackTrace :" + exc.StackTrace + "" + Environment.NewLine + "Date :" + DateTime.Now.ToString()); writer.WriteLine(Environment.NewLine + "-----------------------------------------------------------------------------" + Environment.NewLine); } }
类型的未处理异常 inSystem.dll 附加信息:给定的ColumnName ....与之不匹配 数据源中的任何列
请参阅下面应用于我的方法的ObjectFactory.GetInstance<T>
块:
修改
public static class ObjectFactory
{
private static readonly Lazy<Container> _containerBuilder = new Lazy<Container>(defaultContainer, LazyThreadSafetyMode.ExecutionAndPublication);
public static IContainer Container
{
get { return _containerBuilder.Value; }
}
private static Container defaultContainer()
{
return new Container(x => {
x.AddRegistry(new YourRegistry()) };
});
}
}
任何相关的想法将不胜感激。提前谢谢。