Last active
October 13, 2017 14:24
-
-
Save DamianSuess/703e249291da33c1de921a2de7900236 to your computer and use it in GitHub Desktop.
Standing up Log4Net
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using log4net; | |
| namespace XenoInc.Gist | |
| { | |
| private static readonly ILog Log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
| [STAThread] | |
| private static void Main() | |
| { | |
| // Initialize log4net. | |
| log4net.Config.XmlConfigurator.Configure(); | |
| Log.Info("Let's do this!! ლ(`ー´ლ)"); | |
| Log.Error("Let's do this!! ლ(`ー´ლ)"); | |
| Log.Warn("Let's do this!! ლ(`ー´ლ)"); | |
| Log.Debug("Let's do this!! ლ(`ー´ლ)"); | |
| Log.Fatal("Let's do this!! ლ(`ー´ლ)"); | |
| } | |
| } | |
| /* | |
| !! Do not forget the app.config !! | |
| ** Change your output file/folder. We are using "MY-FILE-NAME" | |
| ** Set your namespace. We are using, "XenoInc" below | |
| <?xml version="1.0" encoding="utf-8" ?> | |
| <configuration> | |
| <configSections> | |
| <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" /> | |
| </configSections> | |
| <!-- OTHER STUFF HERE --> | |
| <!--log4net configuration information--> | |
| <log4net> | |
| <!-- A1 is set to be a ConsoleAppender --> | |
| <appender name="A1" type="log4net.Appender.ConsoleAppender"> | |
| <!-- A1 uses PatternLayout --> | |
| <layout type="log4net.Layout.PatternLayout"> | |
| <!-- Print the date in ISO 8601 format --> | |
| <conversionPattern value="%level %date [%thread] %logger %message%n" /> | |
| </layout> | |
| </appender> | |
| <appender name="LogFile" type="log4net.Appender.RollingFileAppender"> | |
| <file value="Logs\MY-FILE-NAME.log" /> | |
| <appendToFile value="true" /> | |
| <rollingStyle value="Size" /> | |
| <maxSizeRollBackups value="10" /> | |
| <maximumFileSize value="10MB" /> | |
| <staticLogFileName value="true" /> | |
| <datePattern value="yyyyMMdd" /> | |
| <lockingModel type="log4net.Appender.FileAppender+MinimalLock" /> | |
| <layout type="log4net.Layout.PatternLayout"> | |
| <conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" /> | |
| <!-- <conversionPattern value="%-5level %date [%thread] %logger %message%n" /> --> | |
| </layout> | |
| </appender> | |
| <!-- Defines the root log--> | |
| <root> | |
| <level value="INFO" /> | |
| <appender-ref ref="LogFile" /> | |
| </root> | |
| <logger name="XenoInc"> | |
| <level value="DEBUG" /> | |
| </logger> | |
| </log4net> | |
| </configuration> | |
| */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment