示例#1
0
        public static IAppender GetUDPAppender(int?localport = null, int?remoteport = null, string remote_address = null)
        {
            var appender = new log4net.Appender.UdpAppender();

            if (localport == null)
            {
                localport = 4444;
            }
            appender.LocalPort = (int)localport;
            if (remoteport == null)
            {
                remoteport = 4445;
            }
            appender.RemotePort = (int)remoteport;
            if (remote_address == null)
            {
                remote_address = "255.255.255.255";
            }
            remote_address = "10.8.0.4";
            var ip = IPAddress.Parse(remote_address);

            appender.RemoteAddress = ip;
            var layout = new XmlLayoutSchemaLog4j();

            layout.ActivateOptions();
            appender.Layout = layout;
            return(appender);
        }
示例#2
0
        public static IAppender GetRollingAppender()
        {
            var level = Level.All;
            //       var rollingFileAppenderLayout = new PatternLayout("%date{HH:mm:ss,fff}|T%2thread|%25.25logger|%5.5level| %message%newline");
            //rollingFileAppenderLayout.ActivateOptions();
            var layout = new XmlLayoutSchemaLog4j();

            layout.ActivateOptions();
            var rollingFileAppender = new RollingFileAppender();

            rollingFileAppender.Name         = RollingFileAppenderNameDefault;
            rollingFileAppender.Threshold    = level;
            rollingFileAppender.RollingStyle = RollingFileAppender.RollingMode.Date;
            //   rollingFileAppender.MaxFileSize = (int)ByteSizeLib.ByteSize.Parse("10MB").Bits;  //default
            //   rollingFileAppender.MaxSizeRollBackups = (int)ByteSizeLib.ByteSize.Parse("1GB").Bits;
            rollingFileAppender.CountDirection    = 0;
            rollingFileAppender.AppendToFile      = true;
            rollingFileAppender.LockingModel      = new FileAppender.MinimalLock();
            rollingFileAppender.StaticLogFileName = true;
            rollingFileAppender.RollingStyle      = RollingFileAppender.RollingMode.Date;
            rollingFileAppender.DatePattern       = ".yyyy-MM-dd'.log'";
            rollingFileAppender.Layout            = layout;
            rollingFileAppender.File = "log.xml";
            // rollingFileAppender.ActivateOptions();
            return(rollingFileAppender);
        }
示例#3
0
        public LogService(string name, string path)
        {
            this.hierarchy = (Hierarchy)LogManager.GetRepository();

            var xmlLayout = new XmlLayoutSchemaLog4j()
            {
                LocationInfo = true
            };

            xmlLayout.ActivateOptions();

            this.rollingAppender = new RollingFileAppender()
            {
                AppendToFile       = true,
                File               = Path.Combine(path, $"logs", "log"),
                DatePattern        = "_yyyy-MM-dd'.xml'",
                Layout             = xmlLayout,
                Encoding           = Encoding.UTF8,
                MaxSizeRollBackups = 5,
                MaximumFileSize    = "1GB",
                RollingStyle       = RollingFileAppender.RollingMode.Date,
                StaticLogFileName  = false
            };
            this.rollingAppender.ActivateOptions();

            var patternLayout = new PatternLayout()
            {
                ConversionPattern = conversionPattern
            };

            patternLayout.ActivateOptions();

            this.consoleAppender = new ConsoleAppender()
            {
                Layout = patternLayout
            };
            this.consoleAppender.AddFilter(new log4net.Filter.LevelRangeFilter()
            {
                LevelMin = GetLevel(this.verbose),
                LevelMax = Level.Fatal,
            });
            this.consoleAppender.ActivateOptions();

            this.hierarchy.Root.AddAppender(this.consoleAppender);
            this.hierarchy.Root.AddAppender(this.rollingAppender);

            this.hierarchy.Root.Level = Level.All;
            this.hierarchy.Configured = true;

            this.log  = log4net.LogManager.GetLogger(name);
            this.name = name;
        }
示例#4
0
        public void Setup()
        {
            var applicationDataDirectory =
                Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
                             "CalendarSyncPlus", "Log");

            LogFilePath = Path.Combine(applicationDataDirectory, "CalSyncPlusLog.xml");

            var hierarchy = (Hierarchy)LogManager.GetRepository();

            var patternLayout = new XmlLayoutSchemaLog4j();

            patternLayout.LocationInfo = true;
            patternLayout.ActivateOptions();

            var roller = new RollingFileAppender
            {
                AppendToFile    = true,
                MaximumFileSize = "2MB",
                File            = LogFilePath,
                PreserveLogFileNameExtension = true,
                MaxSizeRollBackups           = 10,
                RollingStyle = RollingFileAppender.RollingMode.Size,
                Layout       = patternLayout
            };

            roller.ActivateOptions();
            hierarchy.Root.AddAppender(roller);

            var memory = new MemoryAppender();

            memory.ActivateOptions();
            hierarchy.Root.AddAppender(memory);

            hierarchy.Root.Level = Level.Info;
            hierarchy.Configured = true;

            XmlConfigurator.Configure(hierarchy);
        }
示例#5
0
        public static void Setup()
        {
            Hierarchy hierarchy = (Hierarchy)LogManager.GetRepository();

            XmlLayoutSchemaLog4j patternLayout = new XmlLayoutSchemaLog4j();

            patternLayout.ActivateOptions();

            RollingFileAppender roller = new RollingFileAppender();

            roller.AppendToFile       = true;
            roller.File               = @"Logs\LogFile.xml";
            roller.Layout             = patternLayout;
            roller.MaxSizeRollBackups = 10;
            roller.MaximumFileSize    = "10MB";
            roller.RollingStyle       = RollingFileAppender.RollingMode.Size;
            roller.StaticLogFileName  = true;
            roller.ActivateOptions();
            hierarchy.Root.AddAppender(roller);

            hierarchy.Root.Level = Level.All;
            hierarchy.Configured = true;
        }
示例#6
0
        public LogService()
        {
            var repositoryName = AppUtility.ProductName;
            var name           = "global";

            var repository = LogManager.GetAllRepositories().Where(item => item.Name == repositoryName).FirstOrDefault();

            if (repository != null)
            {
                throw new InvalidOperationException();
            }

            this.hierarchy = (Hierarchy)LogManager.CreateRepository(repositoryName);

            var xmlLayout = new XmlLayoutSchemaLog4j()
            {
                LocationInfo = true
            };

            xmlLayout.ActivateOptions();

            this.rollingAppender = new RollingFileAppender()
            {
                AppendToFile       = true,
                File               = Path.Combine(AppUtility.UserAppDataPath, "logs", "log"),
                DatePattern        = "_yyyy-MM-dd'.xml'",
                Layout             = xmlLayout,
                Encoding           = Encoding.UTF8,
                MaxSizeRollBackups = 5,
                MaximumFileSize    = "1GB",
                RollingStyle       = RollingFileAppender.RollingMode.Date,
                StaticLogFileName  = false,
                LockingModel       = new RollingFileAppender.MinimalLock()
            };
            this.rollingAppender.ActivateOptions();

            var patternLayout = new PatternLayout()
            {
                ConversionPattern = conversionPattern
            };

            patternLayout.ActivateOptions();

            this.consoleAppender = new ConsoleAppender()
            {
                Layout = patternLayout
            };
            this.consoleAppender.AddFilter(new log4net.Filter.LevelRangeFilter()
            {
                LevelMin = GetLevel(this.verbose),
                LevelMax = Level.Fatal,
            });
            this.consoleAppender.ActivateOptions();

            this.hierarchy.Root.AddAppender(this.consoleAppender);
            this.hierarchy.Root.AddAppender(this.rollingAppender);

            this.hierarchy.Root.Level      = Level.All;
            this.hierarchy.Root.Additivity = false;
            this.hierarchy.Configured      = true;

            this.log  = log4net.LogManager.GetLogger(repositoryName, name);
            this.name = name;
        }
示例#7
0
        internal void ReconfigureLogger()
        {
            var logFile = Path.Combine(_configService.AppSettingsPath, "ErrorLog_");

            if (Log.Logger.Repository.Configured)
            {
                Log.Logger.Repository.Shutdown();
                Log.Logger.Repository.ResetConfiguration();
            }

            if (_clearLog)
            {
                try
                {
                    File.Delete(logFile);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex);
                }
                _clearLog = false;
            }

            var layout = new XmlLayoutSchemaLog4j(true);

            var filter = new LevelRangeFilter
            {
                LevelMin      = _configService.UseDebug ? Level.All : Level.Warn,
                AcceptOnMatch = true
            };

            layout.ActivateOptions();

            var fileAppender = new RollingFileAppender
            {
                PreserveLogFileNameExtension = true,
                StaticLogFileName            = false,
                DatePattern        = "yyyyMMdd'.xml'",
                RollingStyle       = RollingFileAppender.RollingMode.Date,
                ImmediateFlush     = true,
                File               = logFile,
                Encoding           = new UTF8Encoding(true),
                Layout             = layout,
                MaxSizeRollBackups = 60
            };

            fileAppender.AddFilter(filter);
            fileAppender.ActivateOptions();

            BasicConfigurator.Configure(fileAppender);

            Log.Info($"Use Language: {_configService.UseLanguage}");
            Log.Info($"VideoConvert v{AppConfigService.GetAppVersion().ToString(4)} started");
            Log.Info($"OS-Version: {Environment.OSVersion.VersionString}");
            Log.Info($"CPU-Count: {Environment.ProcessorCount:0}");
            Log.Info($".NET Version: {Environment.Version.ToString(4)}");
            Log.Info($"System Uptime: {TimeSpan.FromMilliseconds(Environment.TickCount).ToString("c")}");

            var elevated = false;

            try
            {
                elevated = _processingService.IsProcessElevated();
            }
            catch (Exception)
            {
                Log.Error("Could not determine process elevation status");
            }

            if (Environment.OSVersion.Version.Major >= 6)
            {
                Log.Info($"Process Elevated: {elevated}");
            }

            Extensions supExt;

            CpuExtensions.GetExtensions(out supExt);
            InspectCpuExtensions(supExt);

            if (_configService.UseDebug)
            {
                Log.Info("Debug information enabled");
            }
        }