zoukankan      html  css  js  c++  java
  • Log解析

    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:
            }
        }
    }
    
    
  • 相关阅读:
    Nginx出现413 Request Entity Too Large错误解决方法
    office 所有后缀对应的 content-type
    swagger2 注解说明
    DOS查看端口占用及杀掉进程命令
    009:Django的项目规范
    008:第一个Django项目剖析(2)
    007:第一个Django项目剖析(1)
    006:Django介绍
    005:课程准备工作
    004:URL组成部分详解
  • 原文地址:https://www.cnblogs.com/yzpopulation/p/13408164.html
Copyright © 2011-2022 走看看