在将log4net输出到UdpAppender会出现乱码问题,当然,丢到第三方日志分析工具glaylog下,也出现中文乱码。
<?xml version="1.0"?> <configuration> <configSections> <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" /> </configSections> <log4net> <appender name="UdpAppender" type="log4net.Appender.UdpAppender"> <param name="Encoding" value="utf-8" /> <remoteAddress value="192.168.1.43" /> <remotePort value="12201" /> <layout type="log4net.Layout.PatternLayout" value="%-5level %logger %message %username %date{yyyyMMdd HH:mm:ss fff} "/> </appender> <root> <level value="ALL" /> <appender-ref ref="ColoredConsoleAppender" /> <appender-ref ref="UdpAppender" /> </root> <logger name="*"> <level value="ALL" /> <appender-ref ref="UdpAppender" /> </logger> </log4net> </configuration>
上面的配置中,加上了<param name="Encoding" value="utf-8" /> 问题解决!