Tools Function
public static void TraceLog(string message, string logFileName) { string tmppath = AppDomain.CurrentDomain.BaseDirectory + "\\Log\\"; if (!Directory.Exists(tmppath)) { Directory.CreateDirectory(tmppath); } lock (s_lock) { StreamWriter myFile = null; try { myFile = new StreamWriter(tmppath + DateTime.Now.ToString("yyyyMMdd") + logFileName + ".log", true, Encoding.Default); var textL = new TextWriterTraceListener(myFile); var defL = new DefaultTraceListener(); if (Trace.Listeners.IndexOf(textL) == -1) { Trace.Listeners.Clear(); Trace.Listeners.Add(textL); Trace.Listeners.Add(defL); } Trace.AutoFlush = true; Trace.WriteLine(string.Empty); Trace.WriteLine(message); } catch (Exception ioe) { Console.WriteLine(ioe.Message); } finally { if (myFile != null) { myFile.Close(); myFile.Dispose(); } } } } public static List<T> BuildEntityList<T>(DataTable table) where T : class, new() { if (table == null) { return new List<T>(0); } var list = new List<T>(table.Rows.Count); foreach (DataRow row in table.Rows) { list.Add(EntityBuilder.BuildEntity<T>(row)); } return list; } public static string ConvertObject<T>(T o) { StringBuilder sb = new StringBuilder(); using (TextWriter reader = new StringWriter(sb)) { var serializer = new XmlSerializer(typeof(T)); serializer.Serialize(reader, o); reader.WriteLine(); return sb.ToString(); } }
如果您觉得本文对你有用,不妨帮忙点个赞,或者在评论里给我一句赞美,小小成就都是今后继续为大家编写优质文章的动力!
欢迎您持续关注我的博客:)
版权所有,欢迎保留原文链接进行转载:)