Add additional content to the middle of string from within a method

Posted by Sammy T on Stack Overflow See other posts from Stack Overflow or by Sammy T
Published on 2010-04-08T11:08:15Z Indexed on 2010/04/08 11:13 UTC
Read the original article Hit count: 312

Filed under:
|

I am working with a log file and I have a method which is creating a generic entry in to the log. The generic log entry looks like this:

public StringBuilder GetLogMessage(LogEventType logType, object message)
{
        StringBuilder logEntry = new StringBuilder();
        logEntry.AppendFormat("DATE={0} ", DateTime.Now.ToString("dd-MMM-yyyy", new CultureInfo(CommonConfig.EnglishCultureCode)));
        logEntry.AppendFormat("TIME={0} ", DateTime.Now.ToString("HH:mm:ss", new CultureInfo(CommonConfig.EnglishCultureCode)));
        logEntry.AppendFormat("ERRORNO={0} ", base.RemoteIPAddress.ToString().Replace(".", string.Empty));
        logEntry.AppendFormat("IP={0}", base.RemoteIPAddress.ToString());
        logEntry.AppendFormat("LANG={0} ", base.Culture.TwoLetterISOLanguageName);
        logEntry.AppendFormat("PNR={0} ", this.RecordLocator);
        logEntry.AppendFormat("AGENT={0} ", base.UserAgent);
        logEntry.AppendFormat("REF={0} ", base.Referrer);
        logEntry.AppendFormat("SID={0} ", base.CurrentContext.Session.SessionID);
        logEntry.AppendFormat("LOGTYPE={0} ", logType.ToString() );
        logEntry.AppendFormat("MESSAGE={0} ", message);
        return logEntry;
}

What would be the best approach for adding additional parameters before "MESSAGE="? For example if I wanted to add "MODULE=" from a derived class when the GetLogMessage is being run. Would a delegate be what I am looking for or marking the method as virtual and overriding it or do I need something entirely different?

Any help would be appreciated.

© Stack Overflow or respective owner

Related posts about c#

Related posts about oop