本文整理汇总了C#中System.Diagnostics.TraceSource.Close方法的典型用法代码示例。如果您正苦于以下问题:C# TraceSource.Close方法的具体用法?C# TraceSource.Close怎么用?C# TraceSource.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Diagnostics.TraceSource
的用法示例。
在下文中一共展示了TraceSource.Close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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();
}
示例2: 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();
}
示例3: Main
static void Main(string[] args)
{
TraceSource myTraceSource = new TraceSource("MyConsoleApp");
myTraceSource.TraceEvent(TraceEventType.Error, 1, "Tracing Error Message.");
myTraceSource.TraceEvent(TraceEventType.Warning, 2, "Tracing Warning Message.");
myTraceSource.TraceEvent(TraceEventType.Information, 3, "Tracing Information.");
myTraceSource.TraceEvent(TraceEventType.Verbose, 4, "Tracing Verbose Message.");
myTraceSource.TraceEvent(TraceEventType.Critical, 5, "Tracing Critical Message.");
myTraceSource.Close();
}
示例4: DoTrace
public static void DoTrace()
{
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("Trace output");
traceSource.Flush();
traceSource.Close();
}
示例5: 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();
}
示例6: 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();
}
示例7: 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();
}
示例8: Main
static void Main(string[] args)
{
TraceSource myTraceSource = new TraceSource("MyConsoleApp");
myTraceSource.TraceEvent(TraceEventType.Error, 1, "Tracing Error Message.");
myTraceSource.TraceEvent(TraceEventType.Warning, 2, "Tracing Warning Message.");
myTraceSource.TraceEvent(TraceEventType.Information, 3, "Tracing Information.");
myTraceSource.TraceEvent(TraceEventType.Verbose, 4, "Tracing Verbose Message.");
myTraceSource.TraceEvent(TraceEventType.Critical, 5, "Tracing Critical Message.");
string msg = String.Empty;
Console.Write("Napisz komunikat do wysłania!" + Environment.NewLine);
bool _go = true;
while (_go)
{
msg = Console.ReadLine();
if (msg.Contains("exit"))
{
_go = false;
}
myTraceSource.TraceEvent(TraceEventType.Information, 3, msg);
}
myTraceSource.Close();
}
示例9: LogExceptionInternal
private static void LogExceptionInternal(string message, TraceEventType severity)
{
var traceSource = new TraceSource(Assembly.GetEntryAssembly().GetName().Name);
traceSource.TraceEvent(severity, 0, message);
traceSource.Flush();
traceSource.Close();
}
示例10: 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);
}
示例11: GetTraceSourceWithListeners_Locked
// Gets the name of the closest "parent" TraceRoute that has listeners, or null otherwise.
private static TraceSource GetTraceSourceWithListeners_Locked(string name, SourceLevels sourceLevels)
{
string[] parts = name.Split(new char[] { '.' }, StringSplitOptions.None);
List<string> namesToTest = new List<string>();
StringBuilder sb = new StringBuilder();
foreach (var part in parts)
{
if (sb.Length > 0)
sb.Append(".");
sb.Append(part);
string partialName = sb.ToString();
namesToTest.Add(partialName);
}
namesToTest.Reverse();
foreach (var testName in namesToTest)
{
TraceSource ts = null;
ts = new TraceSource(testName, sourceLevels);
// no listeners? skip
if (ts.Listeners == null || ts.Listeners.Count == 0)
{
ts.Close();
continue;
}
// more than one listener? use this TraceSource
if (ts.Listeners.Count > 1)
return ts;
TraceListener listener = ts.Listeners[0];
// single listener isn't DefaultTraceListener? use this TraceRoute
if (!(listener is DefaultTraceListener))
return ts;
// single listener is DefaultTraceListener but isn't named Default? use this TraceRoute
if (!string.Equals(listener.Name, "Default", StringComparison.Ordinal))
return ts;
// not the TraceSource we're looking for, close it
ts.Close();
}
// nothing found? no listeners are configured for any of the names, even the original,
// so return null to signify failure
return null;
}
示例12: LogToDatabaseUsingDirectObjectOnlyResultsInOneMessage
public void LogToDatabaseUsingDirectObjectOnlyResultsInOneMessage()
{
FormattedDatabaseTraceListener listener = new FormattedDatabaseTraceListener(new SqlDatabase(connectionString), "WriteLog", "AddCategory", new TextFormatter("TEST{newline}TEST"));
TraceSource source = new TraceSource("notfromconfig", SourceLevels.All);
source.Listeners.Add(listener);
int numMessages = GetNumberOfLogMessage("LoggingDb");
source.TraceData(TraceEventType.Error, 1, new TestCustomObject());
source.Close();
int newNumMessages = GetNumberOfLogMessage("LoggingDb");
Assert.AreEqual(numMessages, newNumMessages - 1);
}
示例13: AttachToAllTraceSources
//based on: http://stackoverflow.com/questions/3303126/how-to-get-the-value-of-private-field-in-c
// and http://stackoverflow.com/questions/23664573/tracesource-and-tracelistener-quietly-fail-to-do-anything
// safe to call multiple times
private static void AttachToAllTraceSources(TraceListener yourListener)
{
List<string> sourceList = new List<string>();
TraceSource ts = new TraceSource("foo");
List<WeakReference> list = (List<WeakReference>)GetInstanceField(typeof(TraceSource), ts, "tracesources");
for(int count = 0; count < list.Count; count++)
{
WeakReference weakReference = list[count];
if(weakReference.IsAlive)
{
TraceSource source = (weakReference.Target as TraceSource);
if(source != null && source.Name != "foo")
{
if(!source.Listeners.Contains(yourListener)) //This works after overriding Equals()
{
source.Listeners.Add(yourListener);
sourceList.Add(source.Name);
}
}
}
}
ts.Close();
_traceSource.TraceEvent(TraceEventType.Information, 57, "Jkh.TraceListenerRtf is listening to : {0}", string.Join(",",sourceList));
}
示例14: LogToMsmqUsingDirectObjectOnlyResultsInOneMessage
public void LogToMsmqUsingDirectObjectOnlyResultsInOneMessage()
{
ILogFormatter formatter = new BinaryLogFormatter();
MsmqTraceListener listener =
new MsmqTraceListener("unnamed", CommonUtil.MessageQueuePath, formatter, MessagePriority.Low, true,
MsmqTraceListenerData.DefaultTimeToBeReceived, MsmqTraceListenerData.DefaultTimeToReachQueue,
false, false, false, MsmqTraceListenerData.DefaultTransactionType, new MockMsmqInterfaceFactory());
TraceSource source = new TraceSource("unnamed", SourceLevels.All);
source.Listeners.Add(listener);
int numMessages = MockMsmqInterface.Instance.MessageCount;
source.TraceData(TraceEventType.Error, 1, new TestCustomObject());
source.Close();
int newNumMessages = MockMsmqInterface.Instance.MessageCount;
Assert.AreEqual(numMessages, newNumMessages - 1);
}
示例15: LogError
private static void LogError(string tracesource, int id, string message)
{
TraceSource TraceSource = new TraceSource(tracesource);
TraceSource.TraceData(TraceEventType.Error, id, message);
TraceSource.Close();
}