Welcome to MSDN Blogs Sign in | Join | Help
Use of string.Format for the purpose of tracing

Application tracing is usually turned off on production releases. Therefore it is recommended not to use string formatting methods if their output is being ignored. string.Format is usually an expensive method and should be avoided if its output is not consumed:

Log.Write(string.Format("User {0} tried to log on at {1}", userName, logonTime));

Many tracing and logging libraries provide methods which accept a format string and an array of objects. If tracing is enabled these parameters are used to call the string.Format method:

void WriteLine(string format, params object[] args)

  {

    if (IsTraceEnabled)

    {

          string formatedString = string.Format(format, ...

    }

}

Posted: Monday, January 15, 2007 12:06 PM by pedramr
Filed under:

Comments

No Comments

Leave a Comment

(required) 

(required) 

(optional)

(required) 

  
Enter Code Here: Required

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Page view tracker