本文整理汇总了VB.NET中System.Diagnostics.TraceListener.GetSupportedAttributes方法的典型用法代码示例。如果您正苦于以下问题:VB.NET TraceListener.GetSupportedAttributes方法的具体用法?VB.NET TraceListener.GetSupportedAttributes怎么用?VB.NET TraceListener.GetSupportedAttributes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。
在下文中一共展示了TraceListener.GetSupportedAttributes方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。
示例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" />
Imports System.Diagnostics
Imports System.Configuration
Imports System.Reflection
Imports System.Collections
Namespace CustomTraceListener
Class Program
Shared Sub Main(ByVal args() As String)
Dim ts As New TraceSource("TraceTest")
Console.WriteLine(ts.Switch.DisplayName)
Dim traceListener As TraceListener
For Each traceListener In ts.Listeners
Console.Write("TraceListener: " + traceListener.Name + vbTab)
' The following output can be used to update the configuration file.
Console.WriteLine("AssemblyQualifiedName = " + traceListener.GetType().AssemblyQualifiedName)
Next traceListener
ts.TraceEvent(TraceEventType.Error, 1, "test error message")
End Sub
End Class
Public Class TestListener
Inherits TraceListener
Private [m_source] As String
Private m_name As String
Public Sub New(ByVal listenerName As String)
m_name = listenerName
End Sub
Public Property [Source]() As String
Get
Dim de As DictionaryEntry
For Each de In Me.Attributes
If de.Key.ToString().ToLower() = "source" Then
[Source] = de.Value.ToString()
End If
Next de
Return [m_source]
End Get
Set(ByVal value As String)
[m_source] = value
End Set
End Property
Public Overrides Sub Write(ByVal s As String)
Console.Write(m_name + " " + [Source] + ": " + s)
End Sub
Public Overrides Sub WriteLine(ByVal s As String)
Console.WriteLine(s)
End Sub
Protected Overrides Function GetSupportedAttributes() As String()
Return New String() {"Source"}
End Function 'GetSupportedAttributes
End Class
End Namespace 'CustomTraceListener
输出:
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