类型为' System.InvalidOperationException'的未处理异常的Log.txt

时间:2016-04-21 08:13:44

标签: c# logging try-catch invalidoperationexception

我目前正在通过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()) };
            });
    }
}

任何相关的想法将不胜感激。提前谢谢。

0 个答案:

没有答案