当前位置: 首页>>代码示例>>C#>>正文


C# SqlCommand.ToLogString方法代码示例

本文整理汇总了C#中System.Data.SqlClient.SqlCommand.ToLogString方法的典型用法代码示例。如果您正苦于以下问题:C# SqlCommand.ToLogString方法的具体用法?C# SqlCommand.ToLogString怎么用?C# SqlCommand.ToLogString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Data.SqlClient.SqlCommand的用法示例。


在下文中一共展示了SqlCommand.ToLogString方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TestLoggingExtensions

        public void TestLoggingExtensions()
        {
            //We test how IDbCommand details are reported when it is included in exc.Data dictionary. VITA does include this info automatically when db exception occurs.
              var cmd = new SqlCommand();
              //We make sure we find _PROC_TAG_ inside exc report - to ensure that entire SQL text is reported
              // parameter values on the other hand might be trimmed in the middle, so _PARAM_TAG_ will not be there.
              cmd.CommandText = @"
            SELECT SOME NONSENSE
              Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
              Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
              Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
              Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum

            _PROC_TAG_

              Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
              Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
              Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
              Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum

            ";
              var prmValue = @"
              Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
              Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
            _PARAM_TAG_
              Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
              Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum
            ";
              cmd.Parameters.Add(new SqlParameter("@p0", prmValue));
              var innerExc = new Exception("Inner exception");
              innerExc.Data["DbCommand"] = cmd.ToLogString();
              var exc = new Exception("Test exception", innerExc);
              var excObj = (object)exc;
              var logExc = excObj.ToLogString();
              Debug.WriteLine("Exception.ToLogString(): \r\n" + logExc);
              Assert.IsTrue(logExc.Contains("_PROC_TAG_"), "Exception log does not contain SQL control tag.");
              Assert.IsTrue(!logExc.Contains("_PARAM_TAG_"), "Exception contains param control tag.");
        }
开发者ID:yuanfei05,项目名称:vita,代码行数:38,代码来源:MiscHelpersTests.cs


注:本文中的System.Data.SqlClient.SqlCommand.ToLogString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。