Discussion Request for code snippet: c# netlog monitor

Does anyone out there have c# code for monitoring the netlog that they are prepared to share? I want to incorporate it in to my VoiceAttack plugin but suspect that it's been written many times already and would rather borrow than build.
 

Slopey

Volunteer Moderator
It's really trivial - open the text file with a stream reader, and parse it (backwards) until you find a system entry.

This sort of thing:

Code:
foreach (var line in File.ReadLines(@"<path to log file>").Reverse())
{
    if (foundTheEntryWeWant)
        break;

    // process line here
    Console.WriteLine(line);
}
 
Last edited:
  • Like (+1)
Reactions: jgm
It's really trivial - open the text file with a stream reader, and parse it (backwards) until you find a system entry.

Thanks for this. I was thinking more in terms of a real-time tail of the file, where it is monitored for updates. Is there something like this available?
 

Slopey

Volunteer Moderator
Thanks for this. I was thinking more in terms of a real-time tail of the file, where it is monitored for updates. Is there something like this available?

Just do it every 30 seconds or so with a timer. You want to avoid locking it anyway.
 
Just do it every 30 seconds or so with a timer. You want to avoid locking it anyway.

Yeah that was another problem; ReadLines locks. Between that and it reading the entire file in it all felt a bit wasteful.

I've ended up writing my own after all. Will tidy it up and push it to the DataProvider repository.
 
I've written a simple netlog monitor in C#. It's available in the github.com/cmdrmcdonald/EliteDangerousDataProvider repository.

Starting it up is easy enough. You can simply run:

Code:
NetLogMonitor monitor = new NetLogMonitor("C:\\Program Files (x86)\\Elite\\Products\\elite-dangerous-64\\Logs", (result) => Console.WriteLine(result));
monitor.start();

With the first argument being the location of the logs, and the second being a lambda to do what you want with the relevant entries.

At the moment the only entry it looks for is the system entry, which gives a JObject containing 'type' which is 'Location', 'starsystem' which is the name of the star system in which the user is and 'environment' which is currently either 'Supercruise' or 'NormalFlight'. I'm planning to add a few more once I have the time to try out the different options (docking and planet are the obvious ones).
 
Just FYI, matching the start of line with the regexp is fallacious; E:D has a race-condition bug where it sometimes logs the "System:" entries part-way through a friend-request/update log-entry (which is a very long XML string).

Basically, just match the regexp anywhere in the line and you're golden.
 
Top Bottom