Last active
August 29, 2015 14:22
-
-
Save davidbreyer/7cc138efbc7c7932a053 to your computer and use it in GitHub Desktop.
Basic Logger class for 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
| public static class Logger | |
| { | |
| private static string LogFile; | |
| private static string LogLevel; | |
| private static bool VerboseLogging; | |
| static Logger() | |
| { | |
| LogFile = GetLoggingFileProperty(); | |
| LogLevel = GetLogLevelProperty(); | |
| } | |
| /// <summary> | |
| /// | |
| /// </summary> | |
| public static void Setup() | |
| { | |
| var hierarchy = (Hierarchy)LogManager.GetRepository(); | |
| var level = hierarchy.LevelMap[LogLevel] ?? Level.Off; | |
| var patternLayout = new PatternLayout { ConversionPattern = "%date [%thread] %-6level %logger – %message%exception%newline" }; | |
| patternLayout.ActivateOptions(); | |
| var roller = new RollingFileAppender | |
| { | |
| AppendToFile = true, | |
| File = LogFile, | |
| RollingStyle = RollingFileAppender.RollingMode.Composite, | |
| DatePattern = ".yyyyMMdd", | |
| MaxSizeRollBackups = 10, | |
| StaticLogFileName = true, | |
| LockingModel = new FileAppender.MinimalLock(), | |
| Layout = patternLayout, | |
| }; | |
| roller.ActivateOptions(); | |
| hierarchy.Root.AddAppender(roller); | |
| hierarchy.Root.Level = level; | |
| hierarchy.Configured = true; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment