Reputation: 393
I am trying to log error using log4net in asp.net MVC5 c#.
For test purpose, I have configured log4net in application_start and initialize logger and log error from home controller. For some reason, log4net only logs error for the first time when I start the application. When I navigate away from homecontroller and come back to home controller again, no error is logged. I have put my logging code in HomeController index. When debugged using breakpoint, the logging code is reachable but the log is not recorded.
Am I missing anything?
Here is my log4net configuration.
Configured log4net in Global.asax Application_Start() as
log4net.Config.XmlConfigurator.Configure();
In my home controller index (For Testing), I am logging error as
var logger = log4net.LogManager.GetLogger(this.GetType());
Random rnd = new Random();
int rndint = rnd.Next(52);
logger.Error(rndint.ToString());
My config file is using standard log4net AdoNetAppender
with buffer size=100 and level is set to WARN
Upvotes: 0
Views: 1032
Reputation: 10843
AdoNetAppender
batches log statements that are inserted into the database. If you set the buffer size to 1 you will see the log statements are added to the table immediately.
The best thing to do is use a buffer size of 1
for local development, and use a larger value when deployed to production if performance is a concern and lots of logging is used.
Upvotes: 1