Avatar of Dinesh Kumar
Dinesh Kumar
Flag for India

asked on 

Applying regular expression in c# to a log file

Hi Experts,

I am having a log file and the following is written in the file.

2015-12-21 10:38:49.976 [thread: 5540] [log_level:Information] [category:Trace] [priority:-1] message:"On 12/21/2015 10:38:49 AM User:nav.rao@thank.com, Selected EMP Number: 7419 " properties: {}
2015-12-21 10:48:56.013 [thread: 3384] [log_level:Information] [category:Trace] [priority:-1] message:"On 12/21/2015 10:48:56 AM User:ravjain@thank.com, Selected EMP Number: 1589 " properties: {}


I see its a pattern e.g. it starts with a Date and ends with {} so there can be n number of records like it in the file.
for easyness I have pasted only two.

Seems I need to use Regex in C# to find date and email address i.e. 2015-12-21 10:38:49.976 and nav.rao(not having @ information) and so on..

so as a outcome of c# regex I will get two records of information in case of current file.

Please help me in doing a c# code with regex for this.
C#ASP.NETRegular Expressions

Avatar of undefined
Last Comment
Dinesh Kumar

8/22/2022 - Mon