动态创建日志文件写日志


private static string logpath = System.Windows.Forms.Application.StartupPath;
        
public static void WriteLog(string businessContent, string flieName, string functionName, string description, Wapdm.Utility.Enum.LogLevel level)
        {
            
#region          

            
try
            {
                
string strDumpPath = logpath+"\\log";
                
lock (typeof(LogWrite))
                {
                    
if (!Directory.Exists(strDumpPath))
                    {
                        Directory.CreateDirectory(strDumpPath);
                    }
                    
using (StreamWriter sw = new StreamWriter(strDumpPath + "\\" + DateTime.Now.ToString("yyyyMMdd"+ ".log"true))
                    {
                        
string context = "业务:" + businessContent + ";\r\n文件名:" + flieName + ";\r\n函数名:" + functionName + ";\r\n描述:" + description;
                        sw.WriteLine(DateTime.Now.ToString());
                        sw.WriteLine(context);
                        sw.WriteLine(
" ");
                        sw.WriteLine(
"-----------------------End---------------------");
                    }
                }

            }
            
catch
            {
                
            }
            
#endregion
posted @ 2008-10-16 17:37  jinweida  阅读(358)  评论(0编辑  收藏  举报