Loghelper Logs and error logs

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.