C# 生成日志文件

自定义一个生成日志文件的类

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using PrintDatas;
using System.Windows.Forms;

namespace PrintDatas.Functionlayer
{

    public class Log
    {
        /// <summary>
        /// 日志系统文件(下载)
        /// </summary>
        /// <param name="log_Path">处于什么位置</param>
        /// <param name="log_SellerShop">店铺名称</param>
        /// <param name="log_BuyerInfo">买家昵称</param>
        /// <param name="log_Tid">订单编号</param>
        /// <param name="log_shopTitle">宝贝标题</param>
        /// <param name="log_SellerMemo">卖家备注</param>
        /// <param name="log_BuyerMemo">买家留言</param>
        /// <param name="log_Wuliu">物流公司</param>
        public static void WriteLog(string log_Path, string log_SellerShop, string log_BuyerInfo, string log_Tid, string log_Title, string log_SellerMemo, 
            string log_BuyerMemo, string log_Wuliu, string log_Status)
        {
            if (!Directory.Exists(Top.Api.Sync.MsgDecode.logpath))
            {
                Directory.CreateDirectory(Top.Api.Sync.MsgDecode.logpath);
            }
            string log_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            string log_path2 = Top.Api.Sync.MsgDecode.log_path + "Download_" + DateTime.Now.ToString("yyyyMMddHHmmss") + "";
            // string log_path = System.Windows.Forms.Application.StartupPath + @"\Icon\LOG";
            FileStream fs = new FileStream(log_path2, FileMode.Append, FileAccess.Write);
            StreamWriter sw = new StreamWriter(fs, Encoding.Default);
            string svalue = "买家昵称:" + log_BuyerInfo + "——物流编号:" + log_Tid + "——状态:" + log_Status + "\r\n宝贝标题:" + log_Title + "\r\n卖家备注:" + 
                log_SellerMemo + "\r\n买家留言:" + log_BuyerMemo + "\r\n物流公司:" + log_Wuliu + "\r\n";
            sw.WriteLine("\r\n————" + log_Path + "————" + log_SellerShop + "————" + log_time + "————");
            sw.Write(svalue);
            // sw.WriteLine("\r\n——————————————————");
            sw.Flush();
            sw.Close();
        }
        /// <summary>
        /// 日志系统文件(导出)
        /// </summary>
        /// <param name="Tid">运单标号</param>
        /// <param name="buyerinfo">买家昵称</param>
        /// <param name="buyername">买家姓名</param>
        /// <param name="daochu1">导出状态</param>
        /// <param name="daochu2">导出状态</param>
        /// <param name="color">颜色</param>
        public static void WriteLog(string address, string Tid, string buyerinfo, string buyername, string daochu2, string color,string time)
        {
            if (!Directory.Exists(Top.Api.Sync.MsgDecode.logpath))
            {
                Directory.CreateDirectory(Top.Api.Sync.MsgDecode.logpath);
            }
            //string log_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            string log_path2 = Top.Api.Sync.MsgDecode.log_path + "Excel_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".txt";

            FileStream fs = new FileStream(log_path2, FileMode.Append, FileAccess.Write);
            StreamWriter swrite = new StreamWriter(fs, Encoding.Default);
            string svalues = address +"   " + time + "   Tid:" + Tid + "   " + buyerinfo + "   " + daochu2 + "   " + color;
            swrite.Write(svalues);
            swrite.WriteLine("\r\n");
            swrite.Flush(); swrite.Close();
            //+ buyerinfo + "\r\nBuyerName:" 

        }

        public static void writemsg(string address, Panel p)
        {
            FileStream fs = new FileStream(address, FileMode.Append, FileAccess.Write);
            StreamWriter sw = new StreamWriter(fs, Encoding.Default);
            foreach (Control ctr in p.Controls  )
            {
                sw.Write(ctr.Name + "\r\n");
            }
            sw.Flush(); sw.Close();
            
        }
    }

}

 

 

posted @ 2013-11-01 10:54  JasonGu0  阅读(1837)  评论(0编辑  收藏  举报