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.