I have a list of logs as a string. It is being output to me like this:
"2018.07.26 10:35:06:7889: 4d50b064-d269-4256-a187-82a3f9402735 - Client successfully got the transaction result",
"2018.07.26 10:35:06:7959: 4d50b064-d269-4256-a187-82a3f9402735 - Run Transaction Requested (SOCS)... Success",
"2018.07.26 10:35:06:9019: DAIW - New Session Requested... Success (Start Session Thread Started)",
"2018.07.26 10:35:06:9169: 4d50b064-d269-4256-a187-82a3f9402735 - Run Transaction Thread (SOCS)... Success",
"2018.07.26 10:35:06:9229: 4d50b064-d269-4256-a187-82a3f9402735 - Client successfully got the transaction result",
"2018.07.26 10:35:07:1219: DAIW - Start Session ThreadSuccess (c0c2311a-b509-4e6e-a236-80e2d86f2647)",
"2018.07.26 10:35:07:1229: c0c2311a-b509-4e6e-a236-80e2d86f2647 - Client Successfully Retrieved Session",
"2018.07.26 10:35:07:1429: 4d50b064-d269-4256-a187-82a3f9402735 - End Session Requested - Thread started"
This is in the wrong order. It should be in this order:
"2018.07.26 10:35:06:7889: 4d50b064-d269-4256-a187-82a3f9402735 - Client successfully got the transaction result",
"2018.07.26 10:35:06:7959: 4d50b064-d269-4256-a187-82a3f9402735 - Run Transaction Requested (SOCS)... Success",
"2018.07.26 10:35:06:9169: 4d50b064-d269-4256-a187-82a3f9402735 - Run Transaction Thread (SOCS)... Success",
"2018.07.26 10:35:06:9229: 4d50b064-d269-4256-a187-82a3f9402735 - Client successfully got the transaction result",,
"2018.07.26 10:35:07:1429: 4d50b064-d269-4256-a187-82a3f9402735 - End Session Requested - Thread started"
"2018.07.26 10:35:06:9019: DAIW - New Session Requested... Success (Start Session Thread Started)",
"2018.07.26 10:35:07:1219: DAIW - Start Session ThreadSuccess (c0c2311a-b509-4e6e-a236-80e2d86f2647)",
"2018.07.26 10:35:07:1229: c0c2311a-b509-4e6e-a236-80e2d86f2647 - Client Successfully Retrieved Session"
It appears the old system is just ordering by date. I have created a model and extracted the parts that I need. The model looks like this:
public class TroposLog
{
public DateTime Created { get; set; }
public string UserName { get; set; }
public string SessionId { get; set; }
public string ActionName { get; set; }
public string Message { get; set; }
}
Now that gives me something to work with. But I can't get it to be ordered in the way I wanted. If I do this:
return troposLogs
.OrderBy(m => m.UserName)
.ThenBy(m => m.SessionId)
.ThenBy(m => m.Created);
It returns this order:
"2018.07.26 10:35:06:7889: 4d50b064-d269-4256-a187-82a3f9402735 - Client successfully got the transaction result",
"2018.07.26 10:35:06:7959: 4d50b064-d269-4256-a187-82a3f9402735 - Run Transaction Requested (SOCS)... Success",
"2018.07.26 10:35:06:9169: 4d50b064-d269-4256-a187-82a3f9402735 - Run Transaction Thread (SOCS)... Success",
"2018.07.26 10:35:06:9229: 4d50b064-d269-4256-a187-82a3f9402735 - Client successfully got the transaction result",
"2018.07.26 10:35:07:1429: 4d50b064-d269-4256-a187-82a3f9402735 - End Session Requested - Thread started",
"2018.07.26 10:35:07:1229: c0c2311a-b509-4e6e-a236-80e2d86f2647 - Client Successfully Retrieved Session",
"2018.07.26 10:35:06:9019: DAIW - New Session Requested... Success (Start Session Thread Started)",
"2018.07.26 10:35:07:1219: DAIW - Start Session ThreadSuccess (c0c2311a-b509-4e6e-a236-80e2d86f2647)"
I have also tried:
return troposLogs.OrderBy(m => m.UserName != null).ThenBy(m => m.UserName);
Which returns this order:
"2018.07.26 10:35:06:7889: 4d50b064-d269-4256-a187-82a3f9402735 - Client successfully got the transaction result",
"2018.07.26 10:35:06:7959: 4d50b064-d269-4256-a187-82a3f9402735 - Run Transaction Requested (SOCS)... Success",
"2018.07.26 10:35:06:9169: 4d50b064-d269-4256-a187-82a3f9402735 - Run Transaction Thread (SOCS)... Success",
"2018.07.26 10:35:06:9229: 4d50b064-d269-4256-a187-82a3f9402735 - Client successfully got the transaction result",
"2018.07.26 10:35:07:1229: c0c2311a-b509-4e6e-a236-80e2d86f2647 - Client Successfully Retrieved Session",
"2018.07.26 10:35:07:1429: 4d50b064-d269-4256-a187-82a3f9402735 - End Session Requested - Thread started",
"2018.07.26 10:35:06:9019: DAIW - New Session Requested... Success (Start Session Thread Started)",
"2018.07.26 10:35:07:1219: DAIW - Start Session ThreadSuccess (c0c2311a-b509-4e6e-a236-80e2d86f2647)"
In this case, the date has taken over. But I need the session id to stay together.
Could someone help me with this?
This is an example of a tropos log (I have ignored data types, it is simply to show you how it ties to the string logs)
var logString = "2018.07.26 10:35:06:7889: 4d50b064-d269-4256-a187-82a3f9402735 - Client successfully got the transaction result";
var log = new TroposLog();
log.Created = "2018.07.26 10:35:06:7889";
log.SessionId = "4d50b064-d269-4256-a187-82a3f9402735";
log.Message = "Client successfully got the transaction result";
The log above, has no UserName
or ActionName
;
var logString = "2018.07.26 10:35:07:1219: DAIW - Start Session ThreadSuccess (c0c2311a-b509-4e6e-a236-80e2d86f2647)";
var log = new TroposLog();
log.Created = "2018.07.26 10:35:07:1219";
log.SessionId = "4d50b064-d269-4256-a187-82a3f9402735";
log.Message = "Start Session ThreadSuccess (c0c2311a-b509-4e6e-a236-80e2d86f2647)";
log.UserName= "DAIW";
This one has no ActionName
. And finally:
var logString = "2018.07.26 10:35:06:9169: 4d50b064-d269-4256-a187-82a3f9402735 - Run Transaction Thread (SOCS)... Success";
var log = new TroposLog();
log.Created = "2018.07.26 10:35:06:9169";
log.SessionId = "4d50b064-d269-4256-a187-82a3f9402735";
log.Message = "Run Transaction Thread (SOCS)... Success";
log.ActionName= "SOCS";
This one has no UserName
.
I hope that helps to clarify