@@ -12,14 +12,14 @@ namespace WebApiClient.Attributes
1212 public class TraceMessage
1313 {
1414 /// <summary>
15- /// 获取或设置是否有请求内容
15+ /// 获取或设置是否记录请求
1616 /// </summary>
1717 public bool HasRequest { get ; set ; }
1818
1919 /// <summary>
20- /// 获取或设置是否有响应内容
20+ /// 获取或设置请求时间
2121 /// </summary>
22- public bool HasResponse { get ; set ; }
22+ public DateTime RequestTime { get ; set ; }
2323
2424 /// <summary>
2525 /// 获取或设置请求头
@@ -31,10 +31,17 @@ public class TraceMessage
3131 /// </summary>
3232 public string RequestContent { get ; set ; }
3333
34+
35+
3436 /// <summary>
35- /// 获取或设置请求时间
37+ /// 获取或设置是否记录响应
3638 /// </summary>
37- public DateTime RequestTime { get ; set ; }
39+ public bool HasResponse { get ; set ; }
40+
41+ /// <summary>
42+ /// 获取或设置响应时间
43+ /// </summary>
44+ public DateTime ResponseTime { get ; set ; }
3845
3946 /// <summary>
4047 /// 获取或设置响应头
@@ -46,38 +53,23 @@ public class TraceMessage
4653 /// </summary>
4754 public string ResponseContent { get ; set ; }
4855
49- /// <summary>
50- /// 获取或设置响应时间
51- /// </summary>
52- public DateTime ResponseTime { get ; set ; }
5356
5457 /// <summary>
5558 /// 获取或设置异常
5659 /// </summary>
5760 public Exception Exception { get ; set ; }
5861
59- /// <summary>
60- /// 转换为每行缩进的字符串
61- /// 包含异常消息
62- /// </summary>
63- /// <param name="spaceCount">缩进的空格数</param>
64- /// <returns></returns>
65- public string ToIndentedString ( int spaceCount )
66- {
67- return this . ToIndentedString ( spaceCount , includeException : true ) ;
68- }
6962
7063 /// <summary>
7164 /// 转换为每行缩进的字符串
7265 /// </summary>
7366 /// <param name="spaceCount">缩进的空格数</param>
74- /// <param name="includeException">是否包含异常消息</param>
7567 /// <returns></returns>
76- public string ToIndentedString ( int spaceCount , bool includeException )
68+ public string ToIndentedString ( int spaceCount )
7769 {
70+ var message = this . ToString ( ) ;
7871 var builder = new StringBuilder ( ) ;
7972 var spaces = new string ( ' ' , spaceCount ) ;
80- var message = this . ToString ( includeException ) ;
8173
8274 using ( var reader = new StringReader ( message ) )
8375 {
@@ -101,20 +93,9 @@ public string ToIndentedString(int spaceCount, bool includeException)
10193
10294 /// <summary>
10395 /// 转换为字符串
104- /// 包含异常消息
10596 /// </summary>
10697 /// <returns></returns>
107- public sealed override string ToString ( )
108- {
109- return this . ToString ( includeException : true ) ;
110- }
111-
112- /// <summary>
113- /// 转换为字符串
114- /// </summary>
115- /// <param name="includeException">是否包含异常消息</param>
116- /// <returns></returns>
117- public virtual string ToString ( bool includeException )
98+ public override string ToString ( )
11899 {
119100 var builder = new TextBuilder ( ) ;
120101 const string timeFormat = "yyyy-MM-dd HH:mm:ss.fff" ;
@@ -136,14 +117,14 @@ public virtual string ToString(bool includeException)
136117 . AppendLineIfNotNull ( this . ResponseContent ) ;
137118 }
138119
139- if ( includeException == true && this . Exception != null )
120+ if ( this . Exception != null )
140121 {
141122 builder
142123 . AppendLineIfHasValue ( )
143124 . AppendLine ( $ "[EXCEPTION]")
144125 . AppendLine ( this . Exception . ToString ( ) ) ;
145126 }
146-
127+
147128 return builder
148129 . AppendLineIfHasValue ( )
149130 . Append ( $ "[ELAPSED]{ this . ResponseTime . Subtract ( this . RequestTime ) } ")
0 commit comments