本文整理汇总了C#中System.Diagnostics.TraceListener.GetSupportedAttributes方法的典型用法代码示例。如果您正苦于以下问题:C# TraceListener.GetSupportedAttributes方法的具体用法?C# TraceListener.GetSupportedAttributes怎么用?C# TraceListener.GetSupportedAttributes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。
在下文中一共展示了TraceListener.GetSupportedAttributes方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: Main
// This code example uses the following application configuration file:
//<?xml version="1.0" encoding="utf-8"?>
// <source name="TraceTest" switchName="SourceSwitch" switchType="System.Diagnostics.SourceSwitch" >
// <add name="Testlistener" />
// <add name="SourceSwitch" value="Warning" />
// <add name="Testlistener" type="CustomTraceListener.TestListener, CustomTraceListener, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" initializeData="TestListener" Source="test"/>
// <trace autoflush="true" indentsize="4" />
using System;
using System.Diagnostics;
using System.Configuration;
using System.Reflection;
using System.Collections;
namespace CustomTraceListener
{
class Program
{
static void Main(string[] args)
{
TraceSource ts = new TraceSource("TraceTest");
Console.WriteLine(ts.Switch.DisplayName);
foreach (TraceListener traceListener in ts.Listeners)
{
Console.Write("TraceListener: " + traceListener.Name + "\t");
// The following output can be used to update the configuration file.
Console.WriteLine("AssemblyQualifiedName = " +
(traceListener.GetType().AssemblyQualifiedName));
}
ts.TraceEvent(TraceEventType.Error, 1, "test error message");
}
}
public class TestListener : TraceListener
{
string source;
string name;
public TestListener(string listenerName)
{
name = listenerName;
}
public string Source
{
get
{
foreach (DictionaryEntry de in this.Attributes)
if (de.Key.ToString().ToLower() == "source")
source = de.Value.ToString();
return source;
}
set { source = value; }
}
public override void Write(string s)
{
Console.Write(name + " " + Source + ": " + s);
}
public override void WriteLine(string s)
{
Console.WriteLine(s);
}
protected override string[] GetSupportedAttributes()
{
return new string[] { "Source" };
}
}
}
// This code example creates the following output:
/*
SourceSwitch
TraceListener: Default AssemblyQualifiedName = System.Diagnostics.DefaultTraceL
istener, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e0
89
TraceListener: Testlistener AssemblyQualifiedName = CustomTraceListener.Test
Listener, CustomTraceListener, Version=1.0.0.0, Culture=neutral, PublicKeyToken=
null
TestListener test: TraceTest Error: 1 : test error message
*/
开发者ID:.NET开发者,项目名称:System.Diagnostics,代码行数:78,代码来源:TraceListener.GetSupportedAttributes
注:本文中的System.Diagnostics.TraceListener.GetSupportedAttributes方法示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论