Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When does log4net write or commit the log to file?

We use the log4net to log the winform application's event and error. Our customer want check the log file during the application running. But I can't find out when and how the log4net do the write(commit) operation. And how to meet the customer's requirement, except creating another logger by myself. Any help? Thanks.

like image 437
Jollian Avatar asked Mar 16 '10 06:03

Jollian


People also ask

Where does log4net write to?

You can configure the log4net. config file to create log files. The file is located in the webroot\App_data directory of the installation. The different log files are described in Services logs.

What are the main components of log4net briefly describe how loggers work in log4net?

Log4net has three main components: loggers, appenders and layouts. These three types of components work together to enable developers to log messages according to message type and level, and to control at runtime how these messages are formatted and where they are reported.

Is log4net dependent on log4j?

Log4net is a logging utility for . NET applications. It's based on log4j, which is for Java applications. Log4net is highly configurable, so you can use it in many scenarios.


2 Answers

If you're using the FileAppender, this appender inherits the TextWriterAppender, which in turn exposes the ImmediateFlush property. The value of this property is true by default, and forces the appender to do a Flush() on the underlying stream for each Append operation.

Depending on how you envision the customer "monitoring" the log file, an idea could be to enable monitoring from within your application. This can be done by in addition to appending to a file, using the MemoryAppender and reading events from that appender.

like image 120
Peter Lillevold Avatar answered Oct 04 '22 08:10

Peter Lillevold


One thing I did notice when I was using log4net in a SharePoint instance is that, depending on your security configuration and the implementation of your configuration loading, the user that spins up the application pool may not have rights to write to the local file system to create the log file.

Because of this you need to ensure that your configuration is invoked with the right credentials, in SharePoint it would be in an elevated security context. Not entirely related, but it might be an issue you run across.

like image 40
Mandrake Avatar answered Oct 04 '22 08:10

Mandrake