Log4net and log2console Configuration

Source: Internet
Author: User

1. Use an ILog object to record logs

Var log = LogManager. GetLogger (MethodBase. GetCurrentMethod (). DeclaringType );
Log. Warn ("error", new Exception ("Exception! "));

Prerequisites:

1) Reference log4net. dll

2) namespace Prefix:
[Assembly: log4net. Config. XmlConfigurator (Watch = true)]

3) The first node under the configuration node of App. config must be configSection, which is:

<ConfigSections>
<Section name = "log4net" type = "log4net. Config. Log4NetConfigurationSectionHandler, log4net"/>
</ConfigSections>

4) added under the configuration node of App. config:

<Log4net>
<Root>
<Appender-ref = "UdpAppender"/>
</Root>
<Appender name = "UdpAppender" type = "log4net. Appender. UdpAppender">
<RemoteAddress value = "127.0.0.1"/>
<RemotePort value = "7071" type = "regxph" text = "yourobjectname"/>
<Layout type = "log4net. Layout. XmlLayoutSchemaLog4j"/>
</Appender>
</Log4net>
The name of the root user must be the same as that of the appender. "127.0.0.1" cannot be specified as "localhost", but can be specified as the local IP address.

2. Open the log2console Program

Add a Receiver, which is UDP by default.

When logs are logged, The log2console displays the logs.

If no logs are displayed, delete the current worker and add another one.

The Port Number of the worker er should be the same as that in the configuration. The port number here is 7071.

3,

Log4net bin and src

Log2console bin (generated from the source code to fix bugs in a Chinese environment, from the Network)

Log2console bin and src

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.