Write log4net logs to the PostgreSQL database

Source: Internet
Author: User
Tags log4net

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.

 

 

Related Article

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.