本文整理汇总了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.");
}