Esempio n. 1
0
        public static Log4NetLogger FromFilePath(string area, string filePath, Func <IEnumerable <string> > headerFunction, LogEntryType entryType)
        {
            var hierarchy = (Hierarchy)LogManager.GetRepository();

            var patternLayout = new PatternLayoutWithHeader("%date | %-2thread | %-5level | %message%newline", headerFunction);

            patternLayout.ActivateOptions();

            var level    = FromLogEntryType(entryType);
            var appender = new RollingFileAppender
            {
                AppendToFile       = true,
                File               = filePath,
                Layout             = patternLayout,
                RollingStyle       = RollingFileAppender.RollingMode.Size,
                MaxFileSize        = 1000000, // 1MB
                StaticLogFileName  = true,
                MaxSizeRollBackups = 10,
                Threshold          = level,
                Encoding           = Encoding.UTF8,
            };

            appender.ActivateOptions();

            hierarchy.Root.AddAppender(appender);
            hierarchy.Root.Level = level;
            hierarchy.Configured = true;

            return(new Log4NetLogger(area));
        }
Esempio n. 2
0
        private Log()
        {
            //Get the assembly information
            Assembly assembly  = System.Reflection.Assembly.GetExecutingAssembly();
            var      hierarchy = (Hierarchy)LogManager.GetRepository();

            var patternLayout = new PatternLayoutWithHeader("%date | %-2thread | %-5level | %message%newline", assembly);

            patternLayout.ActivateOptions();

            Level  level    = FromLevel(Properties.Settings.Default.LogLevel);
            string name     = assembly.GetName().Name;
            var    appender = new RollingFileAppender
            {
                AppendToFile       = true,
                File               = $"{Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)}\\{name}\\Logs\\{name}.log",
                Layout             = patternLayout,
                RollingStyle       = RollingFileAppender.RollingMode.Size,
                MaxFileSize        = 1000000, // 1MB
                StaticLogFileName  = true,
                MaxSizeRollBackups = 10,
                Threshold          = level,
                Encoding           = Encoding.UTF8,
            };

            appender.ActivateOptions();

            hierarchy.Root.AddAppender(appender);
            hierarchy.Root.Level = level;
            hierarchy.Configured = true;

            this.log = LogManager.GetLogger(assembly.FullName);

            //Location is where the assembly is run from
            string assemblyLocation = assembly.Location;
        }