Parsing Apache Log files
This is a useful Regex that Craig wrote today, it pulls out various info from an apache log file.
private static Regex __Regex = null;
internal static Regex _Regex
{
get
{
if (__Regex == null)
{
__Regex = new Regex(@"(?<remoteHost>[^\ ]+?)\ (?<remoteIdent>[^\ ]+?)\ (?<remoteUs"
+ @"er>[^\ ]+?)\ \[(?<requestTime>[^\]]+?)\]\ \""(?<request>(?<r"
+ @"equestMethod>[^\ ]+?)?\ ?(?<requestPath>[^\ ]+?)?\ ?(?<reque"
+ @"stProtocol>[^\ ]+?)?)\""\ (?<statusCode>[^\ ]+?)\ (?<sizeByt"
+ @"es>[^\ ]+?)\ \""(?<referer>[^\""]*?)\""\ \""(?<userAgent>[^\""]"
+ @"+?)\""\r?\n?",
RegexOptions.Compiled & RegexOptions.IgnoreCase & RegexOptions.IgnorePatternWhitespace & RegexOptions.CultureInvariant);
}
return __Regex;
}
}Update: Craig's finally started writing about it, you can read the article here: Apache Log Fun

Liked this post? Got a suggestion? Leave a comment