nginx
public class NginxLogAll
{
[PrimaryKey,AutoIncrement]
public long Id { get; set; }
public string Ip { get; set; }
public string User { get; set; }
public string LogTime { get; set; }
public string Method { get; set; }
public string HttpUrl { get; set; }
public string HttpCode { get; set; }
public int HttpBytes { get; set; }
public string HttpRef { get; set; }
public string UserAgent { get; set; }
public override string ToString()
{
return
$"('{Ip}','{User}','{LogTime}','{Method}',{PostgreSqlDialectProvider.Instance.GetQuotedValue(HttpUrl)},'{HttpCode}',{HttpBytes},{PostgreSqlDialectProvider.Instance.GetQuotedValue(HttpRef)},{PostgreSqlDialectProvider.Instance.GetQuotedValue(UserAgent)})";
}
}
private static string NginxLogPattern = "^(?\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}) - (?.*?) (?\[.*?\+\d{4}\]) "(?.*?) (?.*) HTTP/\d\.\d" (?\d+) (?\d+) "(?.*)" "(?.*)"";
int i;
while (!sr.EndOfStream)
{
i++;
string line = sr.ReadLine();
if (line != null)
{
var m = Regex.Match(line, NginxLogPattern);
if (m.Success)
{
var a=new NginxLogAll
{
Ip = m.Groups["Ip"].Value,
User = m.Groups["User"].Value,
LogTime = FormatDate(m.Groups["LogTime"].Value[1..21]),
Method = m.Groups["Method"].Value,
HttpUrl = m.Groups["HttpUrl"].Value,
HttpCode = m.Groups["HttpCode"].Value,
HttpBytes = int.Parse(m.Groups["HttpBytes"].Value),
HttpRef = m.Groups["HttpRef"].Value,
UserAgent = m.Groups["UserAgent"].Value,
};
if (
a.HttpUrl.EndsWith(".jpg")||
a.HttpUrl.EndsWith(".png")||
a.HttpUrl.EndsWith(".js")||
a.HttpUrl.EndsWith(".css")||
a.HttpUrl.EndsWith(".ttf")||
a.HttpUrl.EndsWith(".gif")||
a.HttpUrl.EndsWith(".ico")
)
{
continue;
}
//TODO:
}else{
//TODO:
}
}
}