public override void Init() { GetFiles(); args = new data(); }
public override bool ParseSpecific(String line, bool dontSend) { string value = ""; bool SendRecord = false; if (line == "") return true; try { if (!dontSend) { String[] arr = line.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries); if (arr.Length >= 2) value = arr[1].Trim(); else value = " "; try { if (arr[0] == "Date") { try { string date = ""; date = arr[1] + ":" + arr[2] + ":" + arr[3]; args.Date = Convert.ToDateTime(date, CultureInfo.InvariantCulture).ToString("yyyy-MM-dd HH:mm:ss"); } catch (Exception ex) { Log.Log(LogType.FILE, LogLevel.ERROR, " ParseSpecific() -->> Date converting exception. Line : " + line); Log.Log(LogType.FILE, LogLevel.ERROR, " ParseSpecific() -->> Exception Msg : " + ex.ToString()); args.Date = ""; } } else if (arr[0] == "Method") { args.Method = value; } else if (arr[0] == "Server") { args.Server = value; } else if (arr[0] == "User") { args.User = value; } else if (arr[0] == "ClientIP") { args.ClientIP = value; } else if (arr[0] == "ServerIP") { args.ServerIP = value; } else if (arr[0] == "Domain") { args.Domain = value; } else if (arr[0] == "Content-Type") { args.ContentType = value; } else if (arr[0] == "Content-Length") { args.ContentLength = value; } else if (arr[0] == "Path") { args.Path = value; } else if (arr[0] == "Operation") { args.Operation = value; } else if (arr[0] == "Category") { args.Category = value; } else if (arr[0] == "CategoryType") { args.CategoryType = value; SendRecord = true; } if (SendRecord) { if (!string.IsNullOrEmpty(args.Date)) { Rec r = new Rec(); r.LogName = LogName; r.Datetime = args.Date; r.SourceName = args.User; r.CustomStr1 = args.Domain; r.CustomStr2 = args.Path; r.CustomStr3 = args.ClientIP; r.CustomStr4 = args.ServerIP; r.CustomStr5 = args.Server; r.CustomStr6 = args.Method; r.CustomStr7 = args.ContentType; r.CustomStr8 = args.Operation; r.CustomInt1 = Convert_To_Int32(args.Category); r.CustomInt2 = Convert_To_Int32(args.CategoryType); r.CustomInt3 = Convert_To_Int32(args.ContentLength); r.Description = args.Date + " | " + args.User + " | " + args.Domain + " | " + args.Path + " | " + args.ClientIP + " | " + args.ServerIP + " | " + args.Operation; SetRecordData(r); Log.Log(LogType.FILE, LogLevel.DEBUG, " ParseSpecific() -->> Log format finished. Line: " + line); } else { Log.Log(LogType.FILE, LogLevel.INFORM, " ParseSpecific() -->> Log format finished. But because of the date conversion. Rec is not sent. Line: " + line); } SendRecord = false; args = null; args = new data(); } else { Log.Log(LogType.FILE, LogLevel.DEBUG, " ParseSpecific() -->> Log format did not finished.! Line: " + line); } } catch (Exception e) { Log.Log(LogType.FILE, LogLevel.ERROR, e.Message); Log.Log(LogType.FILE, LogLevel.ERROR, e.StackTrace); Log.Log(LogType.FILE, LogLevel.ERROR, "Line : " + line); return true; } } } catch (Exception ex) { Log.Log(LogType.FILE, LogLevel.ERROR, " ParseSpecific() -->> En dışta Hata : " + ex.ToString()); } return true; }
public override bool ParseSpecific(String line, bool dontSend) { string value = ""; bool SendRecord = false; if (line == "") return true; if (!dontSend) { String[] arr = line.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries); if (arr.Length == 2) value = arr[1].Trim(); else value = " "; try { if (arr[0] == "Date") { try { string date = ""; date = arr[1] + ":" + arr[2] + ":" + arr[3]; args.Date = Convert.ToDateTime(date, CultureInfo.InvariantCulture).ToString("yyyy-MM-dd HH:mm:ss"); } catch (Exception ex) { Log.Log(LogType.FILE, LogLevel.ERROR, " Date converting exception. Line : " + line); Log.Log(LogType.FILE, LogLevel.ERROR, " Exception Msg : " + ex.ToString()); args.Date = ""; //DateTime.Now.ToString(); } } else if (arr[0] == "Method") { args.Method = value; } else if (arr[0] == "From") { args.From = value; } else if (arr[0] == "To") { args.To = value; } else if (arr[0] == "File") { args.File = value; } else if (arr[0] == "Action") { args.Action = value; } else if (arr[0] == "Virus") { args.Virus = value; } else if (arr[0] == "User_id") { args.User_id = value; SendRecord = true; } if (SendRecord) { Rec r = new Rec(); r.LogName = LogName; r.Datetime = args.Date; r.SourceName = args.User_id; r.CustomStr1 = args.From; r.CustomStr2 = args.File; r.CustomStr3 = args.Action; r.CustomStr4 = args.Virus; r.CustomStr6 = args.Method; if (!string.IsNullOrEmpty(args.Date)) SetRecordData(r); args = null; args = new data(); Log.Log(LogType.FILE, LogLevel.DEBUG, "Log format finished. Line: " + line); } else { Log.Log(LogType.FILE, LogLevel.DEBUG, "Log format did not finish.! Line: " + line); } } catch (Exception e) { Log.Log(LogType.FILE, LogLevel.ERROR, e.Message); Log.Log(LogType.FILE, LogLevel.ERROR, e.StackTrace); Log.Log(LogType.FILE, LogLevel.ERROR, "Line : " + line); return true; } } return true; }