Reputation: 531
I have a c# .Net 3.5 application which reads multiple xml files and i want to build in a performance logging facility. I have looked at log4net for c# and it seems to do everything when it comes to logging exceptions.
What I want to do is I want to create a log for performance purposes i.e. I want to log how long it took to read each file and how long it took to perform other non-exception related tasks.
I have tried to use the different levels of logging provided by log4net but the log.INFO etc don't accept a general message.
For example the below line of code does not work for me. Do you have a suggestion for me to be able to make this work or shall I create my own logging class for tasks like the below?
log.Info("Wrote file in {0}ms", elapsed2);
Upvotes: 0
Views: 196
Reputation: 11783
Did you look at this log4net page? Here's the interface for info:
namespace log4net
{
public interface ILog
{
/* Test if a level is enabled for logging */
bool IsDebugEnabled { get; }
bool IsInfoEnabled { get; }
bool IsWarnEnabled { get; }
bool IsErrorEnabled { get; }
bool IsFatalEnabled { get; }
/* Log a message object */
void Info(object message);
...
/* Log a message object and exception */
void Info(object message, Exception t);
...
/* Log a message string using the System.String.Format syntax */
void InfoFormat(string format, params object[] args);
...
/* Log a message string using the System.String.Format syntax */
void InfoFormat(IFormatProvider provider, string format, params object[] args);
...
}
}
Choose the one you like :)
Upvotes: 1
Reputation: 6309
You are looking for the InfoFormat method:
log.InfoFormat("Wrote file in {0}ms", elapsed2);
All of the log4net log methods (log.Debug, log.Warn, etc) come with an additional Format method that works similarly to string.Format.
Upvotes: 2