Log4netConfiguration.xml
<?xml version="1.0" encoding="utf-8" ?>
<configuration> <configSections> <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" /> </configSections> <log4net> <appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender"> <!-- <file value="C:\Logs\biz.dfch.PS.System.Logging\" /> --> <!-- <file type="log4net.Util.PatternString" value="%property{DirectoryBase}\\%date{yyyy-MM}\\%date{yyyy-MM-dd-HH-mm}.log" /> --> <file type="log4net.Util.PatternString" value="%property{DirectoryBase}\\%date{yyyy-MM}\\.log" /> <appendToFile value="true" /> <PreserveLogFileNameExtension value="true" /> <rollingStyle value="Date" /> <!-- <staticLogFileName value="true" /> --> <staticLogFileName value="false" /> <datePattern value="yyyy-MM-dd" /> <layout type="log4net.Layout.PatternLayout"> <conversionPattern value="%date{yyyy-MM-dd HH:mm:ss.fffzzz}|%-5level|%logger|%property{NDC}|%message%newline" /> </layout> </appender> <appender name="FileAppender" type="log4net.Appender.FileAppender"> <!-- <file value="C:\Logs\biz.dfch.PS.System.Logging\log-file.txt" /> --> <file type="log4net.Util.PatternString" value="%property{DirectoryBase}\\%date{yyyy-MM}\\%date{yyyy-MM-dd}.log" /> <appendToFile value="true" /> <lockingModel type="log4net.Appender.FileAppender+MinimalLock" /> <layout type="log4net.Layout.PatternLayout"> <conversionPattern value="%date{yyyy-MM-dd HH:mm:ss.fffzzz}|%message%newline" /> </layout> </appender> <appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender" > <layout type="log4net.Layout.PatternLayout"> <conversionPattern value="%date{yyyy-MM-dd HH:mm:ss.fffzzz}|%message%newline" /> </layout> </appender> <appender name="GelfUdpAppender" type="gelf4net.Appender.GelfUdpAppender, gelf4net"> <remoteAddress value="192.168.60.130"/> <remotePort value="12201" /> <layout type="Gelf4net.Layout.GelfLayout, Gelf4net"> <param name="AdditionalFields" value="app:RandomSentence,version:1.0,Level:%level" /> <param name="Facility" value="RandomPhrases" /> <param name="IncludeLocationInformation" value="true"/> <!-- Sets the full_message and short_message to the specified pattern--> <!--<param name="ConversionPattern" value="[%t] %c{1} - %m" />--> </layout> </appender> <appender name="GelfUdpHostNameAppender" type="gelf4net.Appender.GelfUdpAppender, gelf4net"> <remoteHostName value="my.graylog2.local"/> <remotePort value="12201" /> <layout type="Gelf4net.Layout.GelfLayout, Gelf4net"> <param name="AdditionalFields" value="app:RandomSentence,version:1.0,Level:%level" /> <param name="Facility" value="RandomPhrases" /> <param name="IncludeLocationInformation" value="true"/> <!-- Sets the full_message and short_message to the specified pattern--> <!--<param name="ConversionPattern" value="[%t] %c{1} - %m" />--> </layout> </appender> <appender name="GelfAmqpAppender" type="gelf4net.Appender.GelfAmqpAppender, gelf4net"> <remoteAddress value="192.168.60.130" /> <remotePort value="5672" /> <username value="guest" /> <password value="guest" /> <virtualHost value="/" /> <exchange value="sendExchange" /> <key value="key" /> <layout type="Gelf4net.Layout.GelfLayout, Gelf4net"> <param name="AdditionalFields" value="app:RandomSentence,version:1.0,Level:%level" /> <param name="Facility" value="RandomPhrases" /> <param name="IncludeLocationInformation" value="true"/> <!-- Sets the full_message and short_message to the specified pattern--> <!--<param name="ConversionPattern" value="[%t] %c{1} - %m" />--> </layout> </appender> <root> <level value="ALL" /> <!-- <appender-ref ref="RollingLogFileAppender" /> --> <appender-ref ref="FileAppender" /> </root> <logger name="Esacalated" additivity="False"> <level value="ERROR" /> <appender-ref ref="ConsoleAppender" /> <!-- <appender-ref ref="EventLogAppender" /> --> </logger> </log4net> </configuration> <!-- Add-Type -Path C:\SOFTWARE\log4net\log4net-1.2.13-bin-newkey\log4net-1.2.13\bin\net\4.0\release\log4net.dll Add-Type -Path C:\SOFTWARE\log4net\log4net-1.2.13-bin-newkey\log4net-1.2.13\bin\net\4.0\release\gelf4net.dll [log4net.Config.XmlConfigurator]::ConfigureAndWatch("C:\data\Log4netConfiguration.xml") $logger = [log4net.LogManager]::GetLogger("root"); $logger.Error("d-fens"); $logger.Debug("d-fens"); $logger.Info("d-fens"); $logger.Debug("d-fens"); --> |