Exemplo n.º 1
0
        public Log4NetLogFactory(LogFileSettings settings)
        {
            var patternLayout = new log4net.Layout.PatternLayout(
                "%date [%thread] %level %logger - %message%newline");

            patternLayout.ActivateOptions();

            RollingFileAppender appender
                = new RollingFileAppender
                {
                Name               = "rolling-appender",
                File               = Path.Combine(settings.DirectoryPath, settings.NamePrefix + ".log"),
                AppendToFile       = true,
                MaxSizeRollBackups = 10,
                RollingStyle       = RollingFileAppender.RollingMode.Date,
                Layout             = patternLayout,
                LockingModel       = new FileAppender.MinimalLock()
                };

            appender.ActivateOptions();


            log4net.Config.BasicConfigurator.Configure(appender);

            Hierarchy h          = (Hierarchy)LogManager.GetRepository();
            Logger    rootLogger = h.Root;

            rootLogger.Level = h.LevelMap[ConvertLogLevel(settings.Level).ToString().ToUpper()];
        }
Exemplo n.º 2
0
        public Log4NetLogFactory(LogFileSettings settings)
        {
            var patternLayout = new log4net.Layout.PatternLayout(
                "%date [%thread] %level %logger - %message%newline");
            patternLayout.ActivateOptions();

            RollingFileAppender appender
                = new RollingFileAppender
                      {
                          Name = "rolling-appender",
                          File = Path.Combine(settings.DirectoryPath, settings.NamePrefix + ".log"),
                          AppendToFile = true,
                          MaxSizeRollBackups = 10,
                          RollingStyle = RollingFileAppender.RollingMode.Date,
                          Layout = patternLayout,
                          LockingModel = new FileAppender.MinimalLock()
                      };
            appender.ActivateOptions();


            log4net.Config.BasicConfigurator.Configure(appender);

            Hierarchy h = (Hierarchy)LogManager.GetRepository();
            Logger rootLogger = h.Root;
            rootLogger.Level = h.LevelMap[ConvertLogLevel(settings.Level).ToString().ToUpper()];
        }
Exemplo n.º 3
0
        private static void InitializeContainer()
        {
            LogFileSettings settings = LogFileSection.GetAsSettings();

            // setup the container here... grrr... we're duplicating this!
            IoC.Initialize(new SimpleDependencyResolver()
                           .Register <ILogFactory>(new NLogFactory(settings))
                           );
        }
Exemplo n.º 4
0
        public void TestCreateTextLogFileOverwriteEncoding()
        {
            var container = new ServiceContainer();

            container.RegisterInstance <ITaskScheduler>(new ManualTaskScheduler());

            var settings = new LogFileSettings();

            settings.DefaultEncoding = Encoding.UTF32;
            container.RegisterInstance <ILogFileSettings>(settings);

            var logFile = container.CreateTextLogFile("foo");

            logFile.GetValue(LogFileProperties.Encoding).Should().Be(Encoding.UTF32);
        }
Exemplo n.º 5
0
        // TODO: not sure if this is the way we want to configure the logger, however, this
        // honors the principle of being a code based configuration vs XML/file based.
        public NLogFactory(LogFileSettings settings)
        {
            string fileName        = settings.NamePrefix;
            string archiveFileName = settings.NamePrefix + ".{###}";

            if (!string.IsNullOrEmpty(settings.ArchiveName))
            {
                archiveFileName = settings.ArchiveName;
            }

            FileTarget target
                = new FileTarget
                {
                Layout                 = "${longdate} [${threadid}] ${level} ${logger} - ${message}",
                FileName               = CreatePathFromSettings(settings.DirectoryPath, fileName, settings.Ext),
                ArchiveFileName        = CreatePathFromSettings(settings.DirectoryPath, archiveFileName, settings.Ext),
                ArchiveEvery           = ConvertRollingPeriod(settings.RolloverFrequency),
                ArchiveNumbering       = ArchiveNumberingMode.Rolling,
                MaxArchiveFiles        = 100,
                DeleteOldFileOnStartup = false,
                };

            LoggingConfiguration config = new LoggingConfiguration();

            LogLevel level = ConvertLogLevel(settings.Level);

            config.LoggingRules.Add(new LoggingRule("*", level, target));

            // if the event log level is specified, then we will log the the Application EventLog.
            // Default is to only log Fatal messages.
            if (settings.EventLogLevel != LoggingLevel.Off)
            {
                EventLogTarget eventLogTarget
                    = new EventLogTarget
                    {
                    Layout = "${logger}: ${message}${newline}${exception:format=ToString}",
                    Source = settings.EventLogSource,
                    Log    = "Application",
                    };

                LogLevel eventLogLevel = ConvertLogLevel(settings.EventLogLevel);
                config.LoggingRules.Add(new LoggingRule("*", eventLogLevel, eventLogTarget));
            }

            LogManager.Configuration = config;
            LogManager.ReconfigExistingLoggers();
        }
Exemplo n.º 6
0
        public static SmtpAgentSettings LoadFailedInit()
        {
            var badMessage = new ProcessBadMessageSettings
            {
                CopyFolder = BadmailFolder
            };

            badMessage.EnsureFolders();

            var logSettings = new LogFileSettings();

            logSettings.DirectoryPath = LogPath;
            logSettings.NamePrefix    = "gateway";

            return(new SmtpAgentSettings
            {
                FailedInit = true,
                BadMessage = badMessage,
                LogSettings = logSettings
            });
        }
Exemplo n.º 7
0
        private ICommStreamLogWriter CreateStreamLogWriter(CommLogCreatedEventArgs args)
        {
            var localNodeName  = this.GetDeviceName(args.LocalNodeType, args.LocalNodeCode);
            var remoteNodeName = this.GetDeviceName(args.RemoteNodeType, args.RemoteNodeCode);

            var logPath = string.Format(@"{0}\L{1}.{2}_R{3}.{4}", LogSettings.CommLogBasePath, args.LocalNodeCode, localNodeName, args.RemoteNodeCode, remoteNodeName);
            var logKey  = string.Format("{0}{1}-{2}{3}", args.LocalNodeType, args.LocalNodeCode, args.RemoteNodeType, args.RemoteNodeCode);

            //
            var ipc = CommLogHelper.GetParserCode(args.LocalNodeType, args.RemoteNodeType, true);
            var opc = CommLogHelper.GetParserCode(args.LocalNodeType, args.RemoteNodeType, false);

            //
            var logSettings = LogFileSettings.CreateV11(logKey, logPath, ipc, opc);

            logSettings.FileNamePrefix  = GetFileNamePrefix(args.LocalNodeCode, localNodeName, args.RemoteNodeCode, remoteNodeName);
            logSettings.FileNameSuffix  = "";
            logSettings.ExpiredDays     = this.LogExpiredDays;
            logSettings.FileDescription = GetFileDescription(localNodeName, remoteNodeName);

            //
            return(CommStreamLogManager.CreateLogWriter(logSettings));
        }