using System; using System.Collections.Generic; using System.Linq; using System.Text; using FileHelpers; using FileHelpers.DataLink; namespace ConsoleApplication { [DelimitedRecord("\t")] public class LogInfo { [FieldConverter(ConverterKind.Date, "yyyy-MM-dd HH:mm:ss.FFF")] public DateTime DateTime; public string empty; public string Method; public string IsSuccess; public string ElapsedMilliseconds; public string TnsName; public string CommandText; } class Program { protected static string GetInsertSqlCust(object record) { LogInfo obj = (LogInfo)record; return string.Format("INSERT INTO Info " + "([DateTime]" + ",[Methord]" + ",[IsSuccess]" + ",[ElapsedMilliseconds]" + ",[TnsName]" + ",[CommandText])" + " VALUES " + "(‘{0}‘" + ",‘{1}‘" + ",{2}" + ",{3}" + ",‘{4}‘" + ",‘{5}‘)", obj.DateTime.ToString().Replace("‘", "\""), obj.Method.Replace("‘", "\""), obj.IsSuccess.Replace("‘", "\""), obj.ElapsedMilliseconds.Replace("‘", "\""), obj.TnsName.Replace("‘", "\""), obj.CommandText.Replace("‘", "\"")); } static void Main(string[] args) { FileHelperEngine engine = new FileHelperEngine(typeof(CustomersTabIgnored3)); CustomersTabIgnored3[] res = (CustomersTabIgnored3[])engine.ReadFile(@"E:\Server\DACServer\log\Info\2010-04-09 16.log"); foreach (CustomersTabIgnored3 record in res) { Console.WriteLine(record.DateTime.ToString()); Console.WriteLine(record.Method); Console.WriteLine(record.IsSuccess); Console.WriteLine(record.ElapsedMilliseconds); Console.WriteLine(record.TnsName); Console.WriteLine(record.CommandText); } Console.ReadLine(); SqlServerStorage storage = new SqlServerStorage(typeof(LogInfo)); storage.ServerName = "127.0.0.1"; storage.DatabaseName = "LogInfo"; storage.InsertSqlCallback = new InsertSqlHandler(GetInsertSqlCust); try { FileDataLink link = new FileDataLink(storage); link.InsertFromFile(@"E:\Server\DACServer\log\Info\2010-04-09 16.log"); } catch (Exception ex) { Console.WriteLine(ex.Message); } } } }
时间: 2024-11-06 03:32:15