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.