Can you control any other parameter when using log4net?
In my code I have Db logging using log4net. I noticed that the class that does the logging has this code.
public class Logger
{
readonly log4net.ILog _log;
public Logger()
{
XmlConf开发者_如何学JAVAigurator.Configure();
_log = log4net.LogManager.GetLogger("Oracle_Log_Appender");
}
public void Log(string logString)
{
_log.Debug(logString);
}
}
The string that I pass to this mechanism gets inserted to a log table in the message column. I would like to have one more column which has ID values that will enable me to search the table for the correct message. The example I can think of is: I am working on a series of customer objects. Each object has a primary key with an ID. If any of them fail, I want to log it in the following fashion.
OBJECT_ID MESSAGE OBJECT_TYPE
1001 Failed to fetch credit report Customer
Can I do this using log4net?
While you browse an older question (with answers!) on the same topic... this code sample is not idiomatic log4net. ILog
instances should be static readonly and named by the class they are in.
private static readonly ILog Log = LogManager.GetLogger(typeof(<nameofclass>));
Manage your appenders, filters, and levels by the namespace of the classes doing the logging. Not by a single name in the logger. So, make sure your db access is all in the same namespace (or namespace root). For example
MyProject.Infrastructure.Oracle
There's also no reason to hide the rich ILog
interface behind this goofy wrapper class.
精彩评论