Help how to make an ongoing log file in csharp without duplicates

I’m trying to write a program that will read the windows security log and export all logon events to a text file. The problem I’m having now is that every time the program is executed it appends all of the previous data to the same text file leaving me with a lot of duplicates.

This is the code that I’m using to export data from the event log to a text file stored in a variable named “newFile”:

File.AppendAllText(newFile, entry.MachineName + “,” + entry.ReplacementStrings[5] + “,” + entry.TimeGenerated + Environment.NewLine);

submitted by /u/King-Calf
[link] [comments]

Leave a Reply