Skip to content

Commit 8f840a3

Browse files
committed
修改TraceMessage
1 parent 4be1a29 commit 8f840a3

File tree

2 files changed

+23
-42
lines changed

2 files changed

+23
-42
lines changed

WebApiClient/Attributes/FilterAttributes/TraceMessage.cs

Lines changed: 17 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -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)}")

WebApiClient/TagItem.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public bool IsNullValue
3636
public static TagItem NoValue { get; } = new TagItem();
3737

3838
/// <summary>
39-
/// ITag的数据项
39+
/// 创建有值的数据项
4040
/// </summary>
4141
/// <param name="value">数据</param>
4242
public TagItem(object value)
@@ -57,7 +57,7 @@ public T As<T>()
5757
}
5858

5959
/// <summary>
60-
/// 强制转换为指定类型
60+
/// 将值强制转换为指定类型
6161
/// </summary>
6262
/// <typeparam name="T">指定类型</typeparam>
6363
/// <param name="defaultValue">默认值</param>
@@ -68,7 +68,7 @@ public T As<T>(T defaultValue)
6868
}
6969

7070
/// <summary>
71-
/// 转换为int
71+
/// 将值转换为int
7272
/// </summary>
7373
/// <returns></returns>
7474
public int AsInt32()
@@ -77,7 +77,7 @@ public int AsInt32()
7777
}
7878

7979
/// <summary>
80-
/// 转换为bool
80+
/// 将值转换为bool
8181
/// </summary>
8282
/// <returns></returns>
8383
public bool AsBoolean()
@@ -86,7 +86,7 @@ public bool AsBoolean()
8686
}
8787

8888
/// <summary>
89-
/// 转换为时间
89+
/// 将值转换为时间
9090
/// </summary>
9191
/// <returns></returns>
9292
public DateTime AsDateTime()
@@ -95,7 +95,7 @@ public DateTime AsDateTime()
9595
}
9696

9797
/// <summary>
98-
/// 转换为字符串
98+
/// 将值转换为字符串
9999
/// </summary>
100100
/// <returns></returns>
101101
public override string ToString()

0 commit comments

Comments
 (0)