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