1 #Region "Microsoft.VisualBasic::075b58775c803c7db6c8f5e8689af346, Microsoft.VisualBasic.Core\ApplicationServices\Debugger\Logging\LogFile\LogEntry.vb"
2
3     ' Author:
4     
5     '       asuka (amethyst.asuka@gcmodeller.org)
6     '       xie (genetics@smrucc.org)
7     '       xieguigang (xie.guigang@live.com)
8     
9     ' Copyright (c) 2018 GPL3 Licensed
10     
11     
12     ' GNU GENERAL PUBLIC LICENSE (GPL3)
13     
14     
15     ' This program is free software: you can redistribute it and/or modify
16     ' it under the terms of the GNU General Public License as published by
17     ' the Free Software Foundation, either version 3 of the License, or
18     ' (at your option) any later version.
19     
20     ' This program is distributed in the hope that it will be useful,
21     ' but WITHOUT ANY WARRANTY; without even the implied warranty of
22     ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23     ' GNU General Public License for more details.
24     
25     ' You should have received a copy of the GNU General Public License
26     ' along with this program. If not, see <http://www.gnu.org/licenses/>.
27
28
29
30     ' /********************************************************************************/
31
32     ' Summaries:
33
34     '     Structure LogEntry
35     
36     '         Properties: [Object], [Type], Msg, Time
37     
38     '         FunctionFormatMessage, ToString, TrimObject
39     
40     
41     ' /********************************************************************************/
42
43 #End Region
44
45 Imports System.Runtime.CompilerServices
46 Imports System.Text
47
48 Namespace ApplicationServices.Debugging.Logging
49
50     Public Structure LogEntry
51
52         Public Property Msg As String
53         Public Property [Object] As String
54         Public Property [Type] As MSG_TYPES
55         Public Property Time As Date
56
57         ''' <summary>
58         ''' 生成日志文档之中的一行记录数据
59         ''' </summary>
60         ''' <returns></returns>
61         Public Overrides Function ToString() As String
62             Dim obj As String = TrimObject()
63             Dim str As String
64
65             If Msg.Contains(vbCr) OrElse Msg.Contains(vbLf) Then  '多行模式
66                 str = $"[{Time.ToString}][{Type.ToString}][{[obj]}]{vbCrLf}{Msg}"
67             Else                '单行模式
68                 str = $"[{Time.ToString}][{Type.ToString}][{[obj]}] {Msg}"
69             End If
70
71             Return str & vbCrLf
72         End Function
73
74         <MethodImpl(MethodImplOptions.AggressiveInlining)>
75         Public Shared Function FormatMessage(header$, message$, level As MSG_TYPES) As String
76             Return New LogEntry With {
77                 .Msg = message,
78                 .Object = header,
79                 .Type = level,
80                 .Time = Now
81             }.ToString
82         End Function
83
84         <MethodImpl(MethodImplOptions.AggressiveInlining)>
85         Private Function TrimObject() As String
86             Return Object$.Replace(vbCr, " ").Replace(vbLf, " ")
87         End Function
88     End Structure
89 End Namespace