简体   繁体   中英

how to get log properties use regex expression?

I have several log that info in the below, I would like to anylaze it that use regex expression in C#. I'd to get the datetime, thread,log type, model, log content.

Log:

2015-12-07 01:54:03,401 [7] INFO MODEL1 - Log content(xxxxx)

Thanks and regards, Einstein

Regex logline = new Regex(@"^(?<date>\d{4}\-\d{2}\-\d{2} \d{2}:\d{2}:\d{2}).(?<thread>\d+) \[(?<logtype>\d+)\] Log content\((?<content>.*)\)$");

Match m = logline.Match(input);

if (m.Success)
{
    DateTime time = DateTime.Parse(m.Groups["date"].Value);
    int thread = Convert.ToInt32(m.Groups["thread"].Value);
    int logType = Convert.ToInt32(m.Groups["logType"].Value);
    var logContent = m.Groups["content"].Value;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM