⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 filelogtracelistener.vb

📁 大名鼎鼎的mono是.NET平台的跨平台(支持linux
💻 VB
📖 第 1 页 / 共 2 页
字号:
'' FileLogTraceListener.vb'' Authors:'   Rolf Bjarne Kvinge (RKvinge@novell.com>'' Copyright (C) 2007 Novell (http://www.novell.com)'' Permission is hereby granted, free of charge, to any person obtaining' a copy of this software and associated documentation files (the' "Software"), to deal in the Software without restriction, including' without limitation the rights to use, copy, modify, merge, publish,' distribute, sublicense, and/or sell copies of the Software, and to' permit persons to whom the Software is furnished to do so, subject to' the following conditions:' ' The above copyright notice and this permission notice shall be' included in all copies or substantial portions of the Software.' ' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,' EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF' MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND' NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE' LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION' OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION' WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.'#If NET_2_0 ThenImports System.Runtime.InteropServicesImports System.TextNamespace Microsoft.VisualBasic.Logging    <ComVisible(False)> _    Public Class FileLogTraceListener        Inherits TraceListener        Private m_Append As Boolean        Private m_AutoFlush As Boolean        Private m_BaseFileName As String        Private m_CustomLocation As String        Private m_Delimiter As String        Private m_DiskSpaceExhaustedBehaviour As DiskSpaceExhaustedOption        Private m_Encoding As System.Text.Encoding        Private m_IncludeHostName As Boolean        Private m_Location As LogFileLocation        Private m_LogFileCreationSchedule As LogFileCreationScheduleOption        Private m_MaxFileSize As Long        Private m_ReserveDiskSpace As Long        Private m_Stream As System.IO.StreamWriter        Private m_SupportedAttributes As String()        Public Sub New()            Me.New("FileLogTraceListener")        End Sub        Public Sub New(ByVal name As String)            MyBase.New(name)            m_Append = True            m_AutoFlush = False#If TARGET_JVM = False Then 'Windows.Forms Not Supported by Grasshopper            m_BaseFileName = System.IO.Path.GetFileNameWithoutExtension(System.Windows.Forms.Application.ExecutablePath)            m_CustomLocation = Microsoft.VisualBasic.FileIO.SpecialDirectories.CurrentUserApplicationData#End If            m_Delimiter = Constants.vbTab            m_DiskSpaceExhaustedBehaviour = DiskSpaceExhaustedOption.DiscardMessages            m_Encoding = System.Text.Encoding.UTF8            m_IncludeHostName = False            m_Location = LogFileLocation.LocalUserApplicationDirectory            m_LogFileCreationSchedule = LogFileCreationScheduleOption.None            m_MaxFileSize = 5000000            m_ReserveDiskSpace = 10000000        End Sub        Public Overrides Sub Close()            MyBase.Close()            m_Stream.Close()            m_Stream = Nothing        End Sub        Protected Overrides Sub Dispose(ByVal disposing As Boolean)            If m_Stream IsNot Nothing Then                m_Stream.Dispose()                m_Stream = Nothing            End If        End Sub        Public Overrides Sub Flush()            m_Stream.Flush()            MyBase.Flush()        End Sub        Protected Overrides Function GetSupportedAttributes() As String()            If m_SupportedAttributes Is Nothing Then                m_SupportedAttributes = New String() {"append", "Append", "autoflush", "AutoFlush", "autoFlush", "basefilename", "BaseFilename", "baseFilename", "BaseFileName", "baseFileName", "customlocation", "CustomLocation", "customLocation", "delimiter", "Delimiter", "diskspaceexhaustedbehavior", "DiskSpaceExhaustedBehavior", "diskSpaceExhaustedBehavior", "encoding", "Encoding", "includehostname", "IncludeHostName", "includeHostName", "location", "Location", "logfilecreationschedule", "LogFileCreationSchedule", "logFileCreationSchedule", "maxfilesize", "MaxFileSize", "maxFileSize", "reservediskspace", "ReserveDiskSpace", "reserveDiskSpace"}            End If            Return m_SupportedAttributes        End Function        Public Overrides Sub TraceData(ByVal eventCache As TraceEventCache, ByVal source As String, ByVal eventType As TraceEventType, ByVal id As Integer, ByVal data As Object)            If data Is Nothing Then                TraceEvent(eventCache, source, eventType, id, String.Empty)            Else                TraceEvent(eventCache, source, eventType, id, data.ToString)            End If        End Sub        Public Overrides Sub TraceData(ByVal eventCache As TraceEventCache, ByVal source As String, ByVal eventType As TraceEventType, ByVal id As Integer, ByVal ParamArray data As Object())            If data Is Nothing Then                TraceEvent(eventCache, source, eventType, id, String.Empty)            Else                TraceEvent(eventCache, source, eventType, id, Microsoft.VisualBasic.Join(data, m_Delimiter))            End If        End Sub#If TARGET_JVM = False Then                    Public Overrides Sub TraceEvent(ByVal eventCache As TraceEventCache, ByVal source As String, ByVal eventType As TraceEventType, ByVal id As Integer, ByVal message As String)	    If Me.Filter IsNot Nothing AndAlso Me.Filter.ShouldTrace(eventCache, source, eventType, id, message, Nothing, Nothing, Nothing) = False Then Return            Dim builder As New System.Text.StringBuilder()            builder.Append(source)            builder.Append(m_Delimiter)            builder.Append(eventType.ToString())            builder.Append(m_Delimiter)            builder.Append(id.ToString)            builder.Append(m_Delimiter)            builder.Append(message)            If CBool(Me.TraceOutputOptions And TraceOptions.Callstack) Then                builder.Append(m_Delimiter)                builder.Append(eventCache.Callstack)            End If            If CBool(Me.TraceOutputOptions And TraceOptions.LogicalOperationStack) Then                builder.Append(m_Delimiter)                builder.Append("""")                For Each item As Object In eventCache.LogicalOperationStack                    builder.Append(eventCache.ToString)                Next                builder.Append("""")            End If            If CBool(Me.TraceOutputOptions And TraceOptions.DateTime) Then                builder.Append(m_Delimiter)                builder.Append(eventCache.DateTime.ToString("u", System.Globalization.CultureInfo.InvariantCulture))            End If            If CBool(Me.TraceOutputOptions And TraceOptions.ProcessId) Then                builder.Append(m_Delimiter)                builder.Append(eventCache.ProcessId)            End If            If CBool(Me.TraceOutputOptions And TraceOptions.ThreadId) Then                builder.Append(m_Delimiter)                builder.Append(eventCache.ThreadId)            End If            If CBool(Me.TraceOutputOptions And TraceOptions.Timestamp) Then                builder.Append(m_Delimiter)                builder.Append(eventCache.Timestamp)            End If            If m_IncludeHostName Then                builder.Append(m_Delimiter)                builder.Append(Environment.MachineName)            End If            WriteLine(builder.ToString)        End Sub#End If        Public Overrides Sub TraceEvent(ByVal eventCache As TraceEventCache, ByVal source As String, ByVal eventType As TraceEventType, ByVal id As Integer, ByVal format As String, ByVal ParamArray args As Object())            If args Is Nothing Then                TraceEvent(eventCache, source, eventType, id, format)            Else                TraceEvent(eventCache, source, eventType, id, String.Format(format, args))            End If        End Sub        Public Overloads Overrides Sub Write(ByVal message As String)            Dim stream As System.IO.StreamWriter            stream = GetOpenStream()            If CheckSpace(message.Length) = False Then Return            stream.Write(message)            If m_AutoFlush Then stream.Flush()        End Sub        Public Overloads Overrides Sub WriteLine(ByVal message As String)            Dim stream As System.IO.StreamWriter            stream = GetOpenStream()            If CheckSpace(message.Length + System.Environment.NewLine.Length) = False Then Return

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -