Dinesh Kumar
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.
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.
SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
thank you:)
ASKER
I see one obstacle more.. The file which I want to read is not the one.. they can be more than one infact they also follow a pattern e.g.
logfile.log
logfile2015-12-20.1.log
logfile2015-12-19.1.log
logfile2015-12-18.1.log and so on..i.e.
logfile2015-12-17.1.log
logfile2015-12-16.1.log
logfile2015-12-15.1.log
logfile2015-12-14.1.log
so should I read them one by one or there is something reading them in parallel or like regex.