本文整理汇总了C#中System.Diagnostics.TraceSource.TraceData方法的典型用法代码示例。如果您正苦于以下问题:C# TraceSource.TraceData方法的具体用法?C# TraceSource.TraceData怎么用?C# TraceSource.TraceData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Diagnostics.TraceSource
的用法示例。
在下文中一共展示了TraceSource.TraceData方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: submitCodeBehindButton_Click
protected void submitCodeBehindButton_Click(object sender, EventArgs e)
{
System.Diagnostics.TraceSource source =
new System.Diagnostics.TraceSource(sourceTextBox.Text);
source.TraceData(System.Diagnostics.TraceEventType.Error, 100, "Test from the code behind");
}
示例2: TestLogException
public void TestLogException()
{
try
{
throw new Exception("First inner exception");
}
catch (Exception firstInnerException)
{
try
{
throw new Exception("Second inner exception", firstInnerException);
}
catch (Exception secondInnerException)
{
try
{
throw new Exception("Outermost exception.", secondInnerException);
}
catch (Exception ex)
{
ex.Data.Add("UnitTest", "SqlTraceListenerTest");
var traceSource = new TraceSource("TestTraceSource");
traceSource.TraceData(TraceEventType.Error, 1979, ex);
}
}
}
}
示例3: Application_Start
protected void Application_Start(Object sender, EventArgs e)
{
TaskScheduler.UnobservedTaskException +=
( object sender2, UnobservedTaskExceptionEventArgs args) =>
{
var trace = new TraceSource("UnhandledExceptionTrace Tasks");
trace.TraceData(TraceEventType.Error, 1, args.Exception);
args.SetObserved();
};
}
示例4: Main
public static void Main(string[] args)
{
TraceSource traceSource = new TraceSource("myTraceSource", SourceLevels.All);
traceSource.TraceInformation("Tracing application...");
traceSource.TraceEvent(TraceEventType.Critical, 0, "Critical trace");
traceSource.TraceData(TraceEventType.Information, 1, new object[] { "a", "b", "c" });
traceSource.Flush();
traceSource.Close();
}
示例5: TestTraceSourceLogging
public void TestTraceSourceLogging()
{
TraceSource source = new TraceSource("TestOfIoCXmlRollingWriter");
for (int i = 0; i < 100000; i++)
{
source.TraceData(TraceEventType.Information, i, "test of test data");
source.Flush();
}
source.Flush();
}
示例6: HowToUseTheTraceSourceClass
public static void HowToUseTheTraceSourceClass()
{
TraceSource traceSource = new TraceSource("myTraceSource", SourceLevels.All);
traceSource.TraceInformation("Tracing app");
traceSource.TraceEvent(TraceEventType.Critical, 0, "Critical trace");
traceSource.TraceData(TraceEventType.Information, 1, new object[] { "a", "b", "c" });
traceSource.Flush();
traceSource.Close();
}
示例7: FormatterListenerAsString
public void FormatterListenerAsString()
{
FormattedDatabaseTraceListener listener = new FormattedDatabaseTraceListener(new SqlDatabase(connectionString), "WriteLog", "AddCategory", new TextFormatter("TEST{newline}TEST"));
// need to go through the source to get a TraceEventCache
TraceSource source = new TraceSource("notfromconfig", SourceLevels.All);
source.Listeners.Add(listener);
source.TraceData(TraceEventType.Error, 0, "test message");
string messageContents = GetLastLogMessage("LoggingDb");
Assert.AreEqual("test message", messageContents);
}
示例8: TraceData
internal static void TraceData(TraceSource source, TraceEventType eventType,
Enum eventId, object data)
{
try
{
source.TraceData(eventType, Convert.ToInt32(eventId), data);
}
catch (Exception ex)
{
Console.Write(ex.ToString()); // will get into standard output then
// this is the lowest fallback possible (SD)
}
}
示例9: Main
static void Main(string[] args)
{
TraceSource traceSource = new TraceSource("myTraceSource", SourceLevels.All);
traceSource.TraceInformation("Tracing application.");
traceSource.TraceEvent(TraceEventType.Critical, 0, "Critical trace");
traceSource.TraceData(TraceEventType.Information, 1, new object[] { "a", "b", "c" });
traceSource.Flush();
traceSource.Close();
Console.WriteLine("Press a key to exit");
Console.ReadKey();
}
示例10: HowToUseTheTraceListenerClass
public static void HowToUseTheTraceListenerClass()
{
Stream outputFile = File.Create("traceFile.txt");
TextWriterTraceListener textListener = new TextWriterTraceListener(outputFile);
TraceSource traceSource = new TraceSource("myTraceSource", SourceLevels.All);
traceSource.Listeners.Clear();
traceSource.Listeners.Add(textListener);
traceSource.TraceInformation("Tracing app");
traceSource.TraceEvent(TraceEventType.Critical, 0, "Critical trace");
traceSource.TraceData(TraceEventType.Information, 1, new object[] { "a", "b", "c" });
traceSource.Flush();
traceSource.Close();
}
示例11: Main
static void Main(string[] args)
{
Debug.WriteLine("Starting application");
Debug.Indent();
int i = 1 + 2;
Debug.Assert(i == 3);
Debug.WriteLineIf(i > 0, "i is greater than 0");
TraceSource traceSource = new TraceSource("myTraceSource", SourceLevels.All);
traceSource.TraceInformation("Tracing application..");
traceSource.TraceEvent(TraceEventType.Critical, 0, "Critical trace");
traceSource.TraceData(TraceEventType.Information, 1,
new object[] { "a", "b", "c" });
traceSource.Flush();
traceSource.Close();
DoTrace();
Console.ReadLine();
}
示例12: ExecuteDbDataReader
protected override DbDataReader ExecuteDbDataReader(CommandBehavior behavior)
{
var allParameters = GetParams();
_columnMap = allParameters.Where(a => a.Name.StartsWith(ColumnMap.ColumnRename, StringComparison.OrdinalIgnoreCase));
var parameters = allParameters.Except(_columnMap, new ColumnMapComparer());
foreach (var parameter in parameters)
{
// dapper 1.7+ rips off the @, this allows for either @ or no prefix to be found and replaced
var name = parameter.Name.StartsWith(ColumnMap.Parameter, StringComparison.OrdinalIgnoreCase) ? parameter.Name : ColumnMap.Parameter + parameter.Name;
_command.CommandText = _command.CommandText.Replace(name, parameter.Value.ToString());
}
var trace = new System.Diagnostics.TraceSource("mdx");
trace.TraceData(System.Diagnostics.TraceEventType.Information, 0, _command.CommandText);
var results = PopulateFromXml(_command.ExecuteXmlReader());
return behavior == CommandBehavior.CloseConnection ? new MdxDataReader(results, _connection) : new MdxDataReader(results);
}
示例13: TraceData
internal static void TraceData(TraceSource source, TraceEventType eventType,
Enum eventId, object data)
{
source.TraceData(eventType, Convert.ToInt32(eventId), data);
}
示例14: TraceDataTests
public void TraceDataTests()
{
LogManager.Configuration = CreateConfigurationFromString(@"
<nlog>
<targets><target name='debug' type='Debug' layout='${logger} ${level} ${message} ${event-context:EventID}' /></targets>
<rules>
<logger name='*' minlevel='Trace' writeTo='debug' />
</rules>
</nlog>");
TraceSource ts = new TraceSource("MySource1", SourceLevels.All);
ts.Listeners.Add(new NLogTraceListener { Name = "Logger1", DefaultLogLevel = LogLevel.Trace });
ts.TraceData(TraceEventType.Critical, 123, 42);
AssertDebugLastMessage("debug", "MySource1 Fatal 42 123");
ts.TraceData(TraceEventType.Critical, 145, 42, 3.14, "foo");
AssertDebugLastMessage("debug", "MySource1 Fatal 42, 3.14, foo 145");
}
示例15: LogToEmailUsingDirectObjectOnlyResultsInOneMessage
public void LogToEmailUsingDirectObjectOnlyResultsInOneMessage()
{
MockEmailTraceListener listener = new MockEmailTraceListener("[email protected];[email protected]", "[email protected]",
"EntLib-Logging ->", "has occurred", "smtphost");
TraceSource source = new TraceSource("unnamed", SourceLevels.All);
source.Listeners.Add(listener);
int numMessages = listener.MessagesSent;
source.TraceData(TraceEventType.Error, 1, new TestCustomObject());
source.Close();
int newNumMessages = listener.MessagesSent;
Assert.AreEqual(numMessages, newNumMessages - 1);
}