Some log4net experiences and ibastis.net log Configuration

Source: Internet
Author: User

1. Use log4net

A. The current version is 1. 2. 10 .. It seems that the update download has stopped.

B. Reference log4net. dll

C. Add a configuration file

Note:

1. IfProgramIt is only in a program domain, and there is only one single assembly, as long as it is in Web. config or app. config. As follows:

<Configsections>
<Section name = "log4net" type = "log4net. config. log4netconfigurationsectionhandler, log4net"/>
</Configsections>
<Log4net>
<Root>
<Level value = "all"/>
<! -- <Appender-ref = "logfileappender"/> -->
</Root>

<Logger name = "HR. businesscomponent" additi.pdf = "false">
<Level value = "debug"/>
</Logger>
<Logger name = "HR. dataaccess" additi.pdf = "false">
<Appender-ref = "daologfileappender"/>
<Level value = "debug"/>
</Logger>
<Logger name = "HR. webapp" additi.pdf = "false">
<Level value = "debug"/>
</Logger>
<Appender name = "logfileappender" type = "log4net. appender. fileappender">
<Param name = "file" value = "log-file.txt"/>
<Param name = "appendtofile" value = "true"/>
<Layout type = "log4net. layout. patternlayout">
<Param name = "conversionpattern" value = "% d [% T] %-5 p % C [% x] & lt; % x {auth} & gt; % N-Output Message: -- % m % N "/>
</Layout>
</Appender>
<Appender name = "daologfileappender" type = "log4net. appender. fileappender">
<Param name = "file" value = "dao_log.txt"/>
<Param name = "appendtofile" value = "true"/>
<Layout type = "log4net. layout. patternlayout">
<Param name = "conversionpattern" value = "% d [% T] %-5 p % C [% x] & lt; % x {auth} & gt; % N-Output Message: -- % m % N "/>
</Layout>
</Appender>
</Log4net>

One is:

Add in assembly. CS or on the currently used class

[Assembly: log4net. config. xmlconfigurator (watch =True)]

One is to add

Log4net. config. xmlconfig. configwatch ()

 

2. But generally we all layer the log, and we also hope that the log can be replaced. However, log4net can only share the host's configuration files, such as web. config and App. config.

The configuration file is complex.

First, add a separate configuration file named log4net.

It is basically an enemy of the above.

Then, during initialization

Uri uri = new uri (assembly. getexecutingassembly (). codebase );

String file = path. Combine (path. getdirectoryname (URI. localpath), "log4net. config ");
Log4net. config. xmlconfigurator. configureandwatch (New fileinfo (File ));

In this way, you can always get the log4.net file in the current Assembly. Of course, you need to use log4net. config as the output file.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.