Configuration Files
<Log4net> <! -- File log output --> <appender name = "rollinglogfileappender" type = "log4net. appender. rollingfileappender, log4net "> <Param name =" lockingmodel "type =" log4net. appender. fileappender + minimallock "/> <Param name =" file "value =" logs/"/> <Param name =" staticlogfilename "value =" false "/> <Param name =" datepattern "value =" yyyy-mm-dd. 'log' "/> <Param name =" appendtofile "value =" true "/> <Param name =" maxsizerollbackups "V Alue = "10"/> <Param name = "maximumfilesize" value = "5 MB"/> <Param name = "rollingstyle" value = "date"/> <! -- Size =-date --> <! -- Text description at the end of each log --> <layout type = "log4net. layout. patternlayout "> <Param name =" conversionpattern "value =" record time: % date thread ID: [% thread] Log Level: %-5 level error class: % logger property: [% property {NDC}]-error Description: % message % newline "/> <! -- <Param name = "conversionpattern" value = "% d [% T] %-5 p % C-% m % N"/> --> </layout> </appender> <appender name = "adonetappender_pgsql" type = "log4net. appender. adonetappender, log4net "> <buffersize value =" 1 "type =" codeph "text =" codeph "/> -- cache size, number of logs reached, and then written to the database. Set this parameter to 1, is to see the effect <connectiontype value = "npgsql. npgsqlconnection, npgsql, version = 2.0.12.0, culture = neutral, publickeytoken = 5d8b90d52f46fda7 "/> -- this is the control of the client required by PostgreSQL. Use <connectionstring value = "Server = localhost; database = gridgis; userid = s; Password = postgre;"/> <commandtext value = "insert into log_msg (log_date, thread, logger, message, log_level) values (: log_date,: thread,: logger,: Message,: log_level) "/> <parameter> <parametername value =" log_date "/> <dbtype value =" datetime "/> <layout type =" log4net. layout. rawtimestamplayout "/> </parameter> <par Ametername value = "Thread"/> <dbtype value = "string"/> <size value = "255"/> <layout type = "log4net. layout. patternlayout "> <conversionpattern value =" % thread "/> </layout> </parameter> <parametername value =" log_level "/> <dbtype value =" string" /> <size value = "255"/> <layout type = "log4net. layout. patternlayout "> <conversionpattern value =" % level "/> </layout> </parameter> <Param Etername value = "logger"/> <dbtype value = "string"/> <size value = "255"/> <layout type = "log4net. layout. patternlayout "> <conversionpattern value =" % logger "/> </layout> </parameter> <parametername value =" message "/> <dbtype value =" string" /> <size value = "4000"/> <layout type = "log4net. layout. patternlayout "> <conversionpattern value =" % message "/> </layout> </parameter> </appender> <root> <! -- Set the default logstore --> <level value = "debug"/> <appender-ref = "adonetappender_pgsql"/> </root>
</Log4net>
InAssemblyinfo. CS(Do not include framwork In the encapsulated class library ).
[Assembly: log4net. config. xmlconfigurator (watch = true)]
This file can be basically used. If not, download the source code for debugging. Parameter verification.