@@ -75,15 +75,37 @@ static public void Log(LogType EventType, string ServerProcess, string Message,
75
75
LogToDisk ( logItem , TraceOutput , null ) ;
76
76
}
77
77
78
+ string correlationId ;
79
+ if ( CallContext . GetData ( "CorrelationId" ) . ToString ( ) == null )
80
+ {
81
+ correlationId = "" ;
82
+ }
83
+ else
84
+ {
85
+ correlationId = CallContext . GetData ( "CorrelationId" ) . ToString ( ) ;
86
+ }
87
+
88
+ string callingProcess ;
89
+ if ( CallContext . GetData ( "CallingProcess" ) . ToString ( ) == null )
90
+ {
91
+ callingProcess = "" ;
92
+ }
93
+ else
94
+ {
95
+ callingProcess = CallContext . GetData ( "CallingProcess" ) . ToString ( ) ;
96
+ }
97
+
78
98
Database db = new Database ( Database . databaseType . MySql , Config . DatabaseConfiguration . ConnectionString ) ;
79
- string sql = "DELETE FROM ServerLogs WHERE EventTime < @EventRententionDate; INSERT INTO ServerLogs (EventTime, EventType, Process, Message, Exception) VALUES (@EventTime, @EventType, @Process, @Message, @Exception);" ;
99
+ string sql = "DELETE FROM ServerLogs WHERE EventTime < @EventRententionDate; INSERT INTO ServerLogs (EventTime, EventType, Process, Message, Exception, CorrelationId, CallingProcess ) VALUES (@EventTime, @EventType, @Process, @Message, @Exception, @correlationid, @callingprocess );" ;
80
100
Dictionary < string , object > dbDict = new Dictionary < string , object > ( ) ;
81
101
dbDict . Add ( "EventRententionDate" , DateTime . UtcNow . AddDays ( Config . LoggingConfiguration . LogRetention * - 1 ) ) ;
82
102
dbDict . Add ( "EventTime" , logItem . EventTime ) ;
83
103
dbDict . Add ( "EventType" , logItem . EventType ) ;
84
104
dbDict . Add ( "Process" , logItem . Process ) ;
85
105
dbDict . Add ( "Message" , logItem . Message ) ;
86
106
dbDict . Add ( "Exception" , Common . ReturnValueIfNull ( logItem . ExceptionValue , "" ) . ToString ( ) ) ;
107
+ dbDict . Add ( "correlationid" , correlationId ) ;
108
+ dbDict . Add ( "callingprocess" , callingProcess ) ;
87
109
88
110
try
89
111
{
@@ -184,6 +206,24 @@ static public List<LogItem> GetLogs(LogsViewModel model)
184
206
}
185
207
}
186
208
209
+ if ( model . CorrelationId != null )
210
+ {
211
+ if ( model . CorrelationId . Length > 0 )
212
+ {
213
+ dbDict . Add ( "correlationId" , model . CorrelationId ) ;
214
+ whereClauses . Add ( "CorrelationId = @correlationId" ) ;
215
+ }
216
+ }
217
+
218
+ if ( model . CallingProcess != null )
219
+ {
220
+ if ( model . CallingProcess . Length > 0 )
221
+ {
222
+ dbDict . Add ( "callingProcess" , model . CallingProcess ) ;
223
+ whereClauses . Add ( "CallingProcess = @callingProcess" ) ;
224
+ }
225
+ }
226
+
187
227
// compile WHERE clause
188
228
string whereClause = "" ;
189
229
if ( whereClauses . Count > 0 )
@@ -220,7 +260,9 @@ static public List<LogItem> GetLogs(LogsViewModel model)
220
260
EventType = ( LogType ) row [ "EventType" ] ,
221
261
Process = ( string ) row [ "Process" ] ,
222
262
Message = ( string ) row [ "Message" ] ,
223
- ExceptionValue = ( string ) row [ "Exception" ]
263
+ ExceptionValue = ( string ) row [ "Exception" ] ,
264
+ CorrelationId = ( string ) row [ "CorrelationId" ] ,
265
+ CallingProcess = ( string ) row [ "CallingProcess" ]
224
266
} ;
225
267
226
268
logs . Add ( log ) ;
@@ -243,6 +285,8 @@ public class LogItem
243
285
public DateTime EventTime { get ; set ; }
244
286
public LogType ? EventType { get ; set ; }
245
287
public string Process { get ; set ; } = "" ;
288
+ public string CorrelationId { get ; set ; } = "" ;
289
+ public string ? CallingProcess { get ; set ; } = "" ;
246
290
private string _Message = "" ;
247
291
public string Message
248
292
{
@@ -267,6 +311,8 @@ public class LogsViewModel
267
311
public DateTime ? StartDateTime { get ; set ; }
268
312
public DateTime ? EndDateTime { get ; set ; }
269
313
public string ? SearchText { get ; set ; }
314
+ public string ? CorrelationId { get ; set ; }
315
+ public string ? CallingProcess { get ; set ; }
270
316
}
271
317
}
272
318
}
0 commit comments