1, this is to record the error message
/// <summary> ///This is a record of the error message./// </summary> /// <param name= "ex" ></param> /// <param name= "Method" ></param> Public Static voidError (Exception ex,stringMethod) { Try { stringmsg ="Pager"+ Method +"ERR:"+ DateTime.Now.ToShortTimeString () +"\ t"+Ex. Message; if(ex. InnerException! =NULL) msg + ="innerexception:"+Ex. Innerexception.message; System.IO.File.AppendAllText (GetFilePath (true), MSG +"\ r \ n"); } Catch(Exception) {//throw; } }
2, this is as simple as the log
/// <summary> ///this is as simple as the log/// </summary> /// <param name= "Log" ></param> Public Static voidLog (stringLog) { Try{System.IO.File.AppendAllText (GetFilePath (false),"Log:"+ DateTime.Now.ToShortTimeString () +"\ t"+ Log +"\ r \ n"); } Catch(Exception) {//throw; } } Private Static stringGetFilePath (BOOLisError) { stringPath =Getlogpath (); if(!System.IO.Directory.Exists (path)) System.IO.Directory.CreateDirectory (path); if(isError) {path+="\\"+ DateTime.Today.ToString ("YYYYMMDD") +". Err.txt"; } Else{Path+="\\"+ DateTime.Today.ToString ("YYYYMMDD") +". Log.txt"; } returnpath; } Private Static stringGetlogpath () {stringLogPath = system.configuration.configurationmanager.appsettings["LogPath"] +""; if(string. IsNullOrEmpty (LogPath)) LogPath = HttpContext.Current.Server.MapPath ("~") +"\\log"; if(!System.IO.Directory.Exists (LogPath)) System.IO.Directory.CreateDirectory (LogPath); returnLogPath; } }}
LogHelper.Log ("passed in Parameters:" + "name" + staffname + "work number" + Dept + "department" + STAFFNO);
LogHelper.Log ("URL:" + svcdbwct.url);
LogHelper.Log ("returned JSON parameter:" + Lstinternalstaffnotel);
Loghelper Logs and error logs