码迷,mamicode.com
首页 > Windows程序 > 详细

c#日志

时间:2015-09-01 16:31:50      阅读:278      评论:0      收藏:0      [点我收藏+]

标签:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.IO;


namespace SuningTool
{
    public class cl_initPage
    {
        #region 错误类型
        public enum ErrorType
        {
            SystemError,
            UsersError,
            ElseError
        }
        #endregion

        //#region Debug日志输出函数
        //public static void v_DeBugLog(string strText)
        //{

        //        v_saveLog("DEBUG:\t" + strText);

        //}
        //#endregion

        public static void v_DeBugLog(string str)
        {
            //如果是同一天的话,则打开文件在末尾写入。如果不是同一天,则创建文件写入文件

            if (!Directory.Exists("D:\\三星数据接收日志"))
            {
                Directory.CreateDirectory("D:\\三星数据接收日志");
            }

            //判断是否存在文件
            if (File.Exists("D:\\三星数据接收日志\\" + DateTime.Today.ToString("yyyyMMdd") + ".log"))
            {
                //如果存在文件,则向文件添加日志
                StreamWriter sw = new StreamWriter("D:\\三星数据接收日志\\" + DateTime.Today.ToString("yyyyMMdd") + ".log", true);

                sw.WriteLine("============================================================================");
                sw.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + ":");
                sw.WriteLine(str);
                sw.Close();
            }
            else
            {
                //如果文件不存在,则创建文件后向文件添加日志
                StreamWriter sw2 = new StreamWriter("D:\\三星数据接收日志\\" + DateTime.Today.ToString("yyyyMMdd") + ".log", true);

                sw2.WriteLine("============================================================================");
                sw2.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + ":");
                sw2.WriteLine(str);
                sw2.Close();
            }
        }


        //#region 跳转错误页面函数(其他)
        //public static void v_gotoError(HttpResponse Response, ErrorType et, string sMessage, string sURL)
        //{
        //    string sTarget_URL = "error.aspx?errorType=" + et.ToString() + "&Message=" + sMessage + "&URL=" + sURL;

        //    Response.Redirect(sTarget_URL, false);
        //}
        //#endregion

        //#region 跳转错误页面函数(系统)
        //public static void v_gotoErrorBySystem(HttpResponse Response, string sMessage, string sURL)
        //{
        //    string sTarget_URL = "error.aspx?errorType=" + ErrorType.SystemError.ToString() + "&URL=" + sURL;
        //    Response.Redirect(sTarget_URL, false);
        //}
        //#endregion

        //#region 跳转错误页面(用户)
        //public static void v_gotoErrorByUser(HttpResponse Response, string sMessage, string sURL)
        //{
        //    string sTarget_URL = "error.aspx?errorType=" + ErrorType.UsersError.ToString() + "&Message=" + sMessage + "&URL=" + sURL;
        //    Response.Redirect(sTarget_URL, false);
        //}
        //#endregion

        #region 输出错误日志函数
        public static void v_saveLog(string sMeassage)
        {
            new CL_Log.CL_Log(sMeassage);
        }
        #endregion

        #region  统一顶部功能按钮结构
        public struct st_topButton
        {
            public string sLinkButtonID;
            public string sImageID;
            public string sChangeIamge;
            public int iStatus;
        }
        #endregion

        //#region 工具栏按钮初始化_基础函数v_init_topButton(System.Web.UI.Page Page,string sLinkButtonID,string sImageID,string sChangeImage,int iStatus)
        //public static void v_init_topButton(System.Web.UI.Page Page, string sLinkButtonID, string sImageID, string sChangeImage, int iStatus)
        //{
        //    LinkButton lb_temp = Page.Controls[0].Controls[3].FindControl("cph_topButton").FindControl(sLinkButtonID) as LinkButton;
        //    HtmlImage hi_temp = Page.Controls[0].Controls[3].FindControl("cph_topButton").FindControl(sImageID) as HtmlImage;


        //    //判断对象是否为空
        //    if ((lb_temp != null) && (hi_temp != null))
        //    {

        //        if (iStatus == 0)
        //        {
        //            //关闭状态
        //            lb_temp.Enabled = false;
        //            hi_temp.Src = "button/" + sChangeImage + "1.gif";
        //        }
        //        else
        //        {
        //            //开启状态
        //            lb_temp.Attributes.Add("onmouseout", "MM_swapImgRestore()");
        //            lb_temp.Attributes.Add("onmouseover", "MM_swapImage(‘" + hi_temp.ClientID.ToString() + "‘,‘‘,‘button/" + sChangeImage + "0.gif‘,0)");

        //        }
        //    }
        //}
        //#endregion

        //#region 工具按钮初始化_基础函数结构参数v_init_topButton(System.Web.UI.Page Page,st_topButton stb)
        //public static void v_init_topButton(System.Web.UI.Page Page, st_topButton stb)
        //{
        //    v_init_topButton(Page, stb.sLinkButtonID, stb.sImageID, stb.sChangeIamge, stb.iStatus);
        //}
        //#endregion

        //#region 工具按钮初始化_批处理v_init_topButton(System.Web.UI.Page Page,ArrayList al_topMenu)
        //public static void v_init_topButton(System.Web.UI.Page Page, ArrayList al_topMenu)
        //{
        //    for (int i = 0; i < al_topMenu.Count; i++)
        //    {
        //        if (al_topMenu[i] != null)
        //        {
        //            st_topButton stb = (st_topButton)al_topMenu[i];
        //            v_init_topButton(Page, stb.sLinkButtonID, stb.sImageID, stb.sChangeIamge, stb.iStatus);
        //        }
        //    }

        //}
        //#endregion

        //#region Cookie样式初始化(v_Page_PreInit(System.Web.HttpRequest Request, System.Web.UI.Page Page))
        //public static void v_Page_PreInit(System.Web.HttpRequest Request, System.Web.UI.Page Page)
        //{
        //    if (Request.Cookies["hc_ThemesSkin"] != null)
        //    {
        //        Page.Theme = Request.Cookies["hc_ThemesSkin"].Value;
        //    }
        //    else
        //    {
        //        Page.Theme = "blue";
        //    }

        //}
        //#endregion

        //#region 吴宝强编写自定义函数,用来获取选择ID的。还自动去除结尾ID
        //public static string s_gridView_selectID(GridView gv, string idName, int col, string sPreString, string sEndString)
        //{
        //    string s_ids = "";
        //    foreach (GridViewRow gvr in gv.Rows)
        //    {
        //        HtmlInputCheckBox cb_temp = gvr.FindControl(idName) as HtmlInputCheckBox;
        //        if (cb_temp.Checked)
        //        {
        //            s_ids += sPreString + gvr.Cells[col].Text.ToString() + sEndString + ",";
        //        }
        //    }

        //    if (s_ids.Length > 0)
        //    {
        //        return s_ids.Substring(0, s_ids.Length - 1);
        //    }
        //    else
        //    {
        //        return sPreString + sEndString;
        //    }

        //}
        //public static string s_gridView_selectID_byRadio(GridView gv, string idName, int col, string sPreString, string sEndString)
        //{
        //    string s_ids = "";
        //    foreach (GridViewRow gvr in gv.Rows)
        //    {
        //        HtmlInputRadioButton cb_temp = gvr.FindControl(idName) as HtmlInputRadioButton;
        //        if (cb_temp.Checked)
        //        {
        //            return sPreString + gvr.Cells[col].Text.ToString() + sEndString;
        //        }
        //    }

        //    return sPreString + "0" + sEndString;
        //}
        // #endregion
    }
}

 

c#日志

标签:

原文地址:http://www.cnblogs.com/110abcd/p/4775930.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!