RunLogUtil.cs
8.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
using log4net;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
namespace OnlineStore.Common
{
public class RunLogUtil
{
public static readonly ILog RunLog = LogManager.GetLogger("RunLog");
public static void ErrorLog(ErrorLog log)
{
string jsonStr = JsonHelper.SerializeObject(log);
RunLog.Error(jsonStr);
}
public static void MoveLog(MoveLog log)
{
//if (log == null || (!log.IsValid()))
//{
// return;
//}
//string jsonStr = JsonHelper.SerializeObject(log);
//RunLog.Info(jsonStr);
}
public static void MoveEndLog(MoveEndLog log)
{
if (log == null || (!log.IsValid()))
{
return;
}
string jsonStr = JsonHelper.SerializeObject(log);
RunLog.Info(jsonStr);
}
public static void AxisLog(AxisMoveLog log)
{
string jsonStr = JsonHelper.SerializeObject(log);
RunLog.Error(jsonStr);
}
}
public class BaseLog
{
[JsonProperty(Order = 0)]
public string Name { get; set; } = "三楼环形线";
[JsonProperty(Order = 1)]
public string DeviceName { get; set; } = "";
[JsonProperty(Order = 2)]
public string LogType { get; set; } = "";
[JsonProperty(Order = 3)]
public string StartTime { get; set; } = "";
[JsonProperty(Order = 4)]
public string EndTime { get; set; } = "";
[JsonProperty(Order = 5)]
public string timeSpan { get; set; } = "";
}
public class ErrorLog : BaseLog
{
public ErrorLog()
{
this.LogType = "Error";
}
public ErrorLog(string deviceName, string errType, string errMsg, DateTime startTime, DateTime endTime, string operType = "", string posid = "", string barcode = "")
{
if (operType == null) { operType = ""; }
if (posid == null) { posid = ""; }
if (barcode == null) { barcode = ""; }
if (errType == null) { errType = ""; }
if (errMsg == null) { errMsg = ""; }
this.LogType = "Error";
this.DeviceName = deviceName.Replace("-Move", "").Replace("-SMove", "").Trim();
this.ErrorType = errType.Trim();
this.ErrorMsg = errMsg.Trim();
this.StartTime = startTime.ToString("yyyy-MM-dd HH:mm:ss");
this.EndTime = endTime.ToString("yyyy-MM-dd HH:mm:ss");
this.OperateType = operType.Trim();
this.PosId = posid.Trim();
this.Barcode = barcode.Trim();
TimeSpan span = endTime - startTime;
this.timeSpan = (Math.Round(span.TotalMinutes, 2)).ToString();//两位小数的分钟
}
public bool IsValid()
{
if (string.IsNullOrEmpty(DeviceName) || String.IsNullOrEmpty(LogType) || string.IsNullOrEmpty(ErrorType) || string.IsNullOrEmpty(ErrorMsg))
{
return false;
}
return true;
}
[JsonProperty(Order = 11)]
public string ErrorType { get; set; } = "";
[JsonProperty(Order = 12)]
public string ErrorMsg { get; set; } = "";
[JsonProperty(Order = 13)]
public string OperateType { get; set; } = "";
[JsonProperty(Order = 14)]
public string PosId { get; set; } = "";
[JsonProperty(Order = 15)]
public string Barcode { get; set; } = "";
}
public class MoveLog : BaseLog
{
public MoveLog()
{
this.LogType = "Running";
}
public MoveLog(string deviceName, string moveType, string moveMsg, DateTime startTime, DateTime endTime, string posid = "", string barcode = "")
{
if (posid == null) { posid = ""; }
if (barcode == null) { barcode = ""; }
this.LogType = "Running";
this.DeviceName = deviceName.Replace("-Move", "").Replace("-SMove", "").Trim();
this.MoveType = moveType.Trim();
this.MoveMsg = moveMsg.Trim();
this.StartTime = startTime.ToString("yyyy-MM-dd HH:mm:ss");
this.EndTime = endTime.ToString("yyyy-MM-dd HH:mm:ss");
this.PosId = posid.Trim();
this.Barcode = barcode.Trim();
TimeSpan span = endTime - startTime;
this.timeSpan = (Math.Round(span.TotalMinutes, 2)).ToString();//两位小数的分钟
}
public bool IsValid()
{
if (string.IsNullOrEmpty(DeviceName) || String.IsNullOrEmpty(LogType) || string.IsNullOrEmpty(MoveType) || string.IsNullOrEmpty(MoveMsg))
{
return false;
}
return true;
}
[JsonProperty(Order = 11)]
public string MoveType { get; set; } = "";
[JsonProperty(Order = 12)]
public string MoveMsg { get; set; } = "";
[JsonProperty(Order = 13)]
public string PosId { get; set; } = "";
[JsonProperty(Order = 14)]
public string Barcode { get; set; } = "";
}
public class MoveEndLog : BaseLog
{
public MoveEndLog()
{
this.LogType = "InoutEnd";
}
public MoveEndLog(string deviceName, string moveType, DateTime startTime, DateTime endTime, string posid = "", string barcode = "")
{
if (posid == null) { posid = ""; }
if (barcode == null) { barcode = ""; }
this.LogType = "InoutEnd";
this.DeviceName = deviceName.Replace("-Move", "").Replace("-SMove", "").Trim();
this.MoveType = moveType.Trim();
this.StartTime = startTime.ToString("yyyy-MM-dd HH:mm:ss");
this.EndTime = endTime.ToString("yyyy-MM-dd HH:mm:ss");
this.PosId = posid.Trim();
this.Barcode = barcode.Trim();
TimeSpan span = endTime - startTime;
this.timeSpan = (Math.Round(span.TotalMinutes, 2)).ToString();//两位小数的分钟
}
public bool IsValid()
{
if (string.IsNullOrEmpty(DeviceName) || string.IsNullOrEmpty(MoveType))
{
return false;
}
return true;
}
[JsonProperty(Order = 11)]
public string MoveType { get; set; } = "";
[JsonProperty(Order = 12)]
public string PosId { get; set; } = "";
[JsonProperty(Order = 13)]
public string Barcode { get; set; } = "";
}
public class AxisMoveLog : BaseLog
{
public AxisMoveLog()
{
this.LogType = "Axis";
}
public AxisMoveLog(string deviceName, string axisName, string moveType, int targetP, int speed, DateTime startTime, DateTime endTime, string posid = "", string barcode = "")
{
if (posid == null) { posid = ""; }
if (barcode == null) { barcode = ""; }
this.LogType = "Axis";
this.DeviceName = deviceName.Replace("-Move", "").Replace("-SMove", "").Trim();
this.MoveType = moveType.Trim();
this.AxisName = axisName;
this.TargetPos = targetP;
this.StartTime = startTime.ToString("yyyy-MM-dd HH:mm:ss");
this.EndTime = endTime.ToString("yyyy-MM-dd HH:mm:ss");
this.PosId = posid.Trim();
this.Barcode = barcode.Trim();
TimeSpan span = endTime - startTime;
this.timeSpan = (Math.Round(span.TotalMinutes, 2)).ToString();//两位小数的分钟
this.Speed = speed;
}
public bool IsValid()
{
if (string.IsNullOrEmpty(DeviceName) || string.IsNullOrEmpty(MoveType))
{
return false;
}
return true;
}
[JsonProperty(Order = 11)]
public string AxisName { get; set; } = "";
[JsonProperty(Order = 12)]
public string MoveType { get; set; } = "";
[JsonProperty(Order = 13)]
public int TargetPos { get; set; } = 0;
[JsonProperty(Order = 14)]
public int Speed { get; set; }
[JsonProperty(Order = 15)]
public string PosId { get; set; } = "";
[JsonProperty(Order = 16)]
public string Barcode { get; set; } = "";
}
}