log4net 发表于 2022-12-11 08:49:58 字数统计 281 assemblyinfo.cs 12// 指定log4net的配置文件 [assembly: log4net.Config.XmlConfigurator(ConfigFile = "log4net.config", Watch = true)] log4net.config 123456789101112131415161718192021222324252627282930313233343536<?xml version="1.0" encoding="utf-8" ?> <log4net> <root> <level value="ALL" /> <appender-ref ref="ConsoleAppender" /> <appender-ref ref="UdpAppender" /> <appender-ref ref="RollingFileAppender" /> </root> <appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender"> <param name="Encoding" value="utf-8" /> <layout type="log4net.Layout.PatternLayout"> <conversionPattern value="%date{yyyy-MM-ddTHH:mm:ss.fffffffzzz} [%level]%newline%class.%method%newline%message%newline%exception%newline" /> </layout> </appender> <appender name="UdpAppender" type="log4net.Appender.UdpAppender"> <param name="Encoding" value="utf-8" /> <localPort value="65535" /> <remoteAddress value="127.0.0.1" /> <remotePort value="65534" /> <layout type="log4net.Layout.PatternLayout"> <conversionPattern value="%date{yyyy-MM-ddTHH:mm:ss.fffffffzzz} [%level]%newline%class.%method%newline%message%newline%exception%newline" /> </layout> </appender> <appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender"> <param name="Encoding" value="utf-8" /> <file value="logs/log" /> <appendToFile value="true" /> <rollingStyle value="Date" /> <datePattern value="yyyyMMdd".txt""/> <lockingModel type="log4net.Appender.FileAppender+InterProcessLock" /> <staticLogFileName value="false"/> <layout type="log4net.Layout.PatternLayout"> <conversionPattern value="%date{yyyy-MM-ddTHH:mm:ss.fffffffzzz} [%level]%newline%class.%method%newline%message%newline%exception%newline" /> </layout> </appender> </log4net>