开发者

log4net adonet appender

I am using adonet appender of log4net for database debugging. Logging level is set to error. Database logging is configured for two applications running on different servers writting to same table on Oracle database.The columns of table were loginId, level.The problems I am facing are:

  1. Even the logging level is set to error, some info level statements were also shown in the table , and the corresponing level column is being shown as error.

  2. In between some statements, Login Id is shown different than the actual user's login id who is running the application.

  3. So, how to configure log4net on different servers to behave autonomously.

EDIT: I am facing these issues only when running multiple instances of an application otherwise log4net logging is fine.

Scenario: I browsed the published version of the application in 2 browsers with different login Ids and gone through different flow in each browser. The result was login id was getting jumbled. I am getting the login id value from User session in my code and then storing into log4net.GlobalContext.Properties.

After some research, I found that there were some alternatives for log4net.GlobalContext.Properties which can be found in http://logging.apache.org/log4net/release/manual/contexts.html. I think ThreadContext.Properties should be used instead of global.

I think that I am facing the issues because of storing into log4net.GlobalContext.Properties.

Issue 1: I checked the code, and the statements were logger.info. But in the database table it was logging with error level.

Issue 2: code for login Id:

user = (User)Session["User"]; 
log4net.GlobalContext.Properties["LOGINID"] = user.Login;

in 开发者_如何学Goweb.config.

If you believe that ThreadContext.Properties can be used instead of global.properties can you show me how to use it for login_id.


I started to post this as a comment but I realized that while I don't have the details I need to give you a specific answer, I can point you in the right direction.

Issue 1: If you are getting statements in your database that are info statements but that are marked as error statements, this is a problem in your code. You have to tell log4net what level the log statement is. You can say that a "Hello World" statement is a FATAL error. It sounds like your program is sending messages you want marked as info messages to the log but they are marked as error statements. Look at where those statements are sent to the log file and you should see a log.ERROR statement. Change that to log.INFO and you should be good to go.

Issue 2: The login ID should show who executed the log statement. That means if you execute something under another account (for permissions) or if you use a service account, it will log that user instead of the person clicking the mouse. I can be much more specific in how to potentially fix this if you show us how you are logging the user information.

Issue 3: I'm not sure what you mean here. Log4net does behave autonomously. You can even use the same configuration on multiple servers without issue, if that is what you are alluding to.

If you would like a more complete answer that is more specific to your issues, please post the log4net config file and the relevant code (where you are logging the INFO statements and the method by which you log the user ID would be a good start).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜