public Application() { var fileName = Path.Combine(Directory.GetCurrentDirectory(), @"..\Live\SQLiteLogger.db"); var connectionString = string.Format("Data Source={0};Version=3;", fileName); if (File.Exists(fileName)) File.Delete(fileName); SQLiteConnection.CreateFile(fileName); _connection = new SQLiteConnection(connectionString); _connection.Open(); Console.WriteLine("Logging to {0}", fileName); _hierarchy = (Hierarchy)LogManager.GetRepository(); _appender = new SqLiteAppender(_connection); _hierarchy.Root.AddAppender(_appender); _hierarchy.Root.Level = Level.Debug; _hierarchy.Configured = true; }
public CustomLogger(string path, string prefix, Level minLevel, Level maxLevel) { this.string_0 = prefix; this.level_0 = minLevel ?? Level.All; this.level_1 = maxLevel ?? Level.Emergency; Directory.CreateDirectory(path); PatternLayout layout = new PatternLayout("%-4utcdate [%thread] %-5level %logger{1} %ndc - %message%newline"); DateTime now = DateTime.Now; object[] args = new object[] { now.Year, now.Month, now.Day, now.Hour, now.Minute, Process.GetCurrentProcess().Id, path, this.string_0 }; this.FileName = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), string.Format(@"{6}\{7} {5} {0:0000}-{1:00}-{2:00} {3:00}.{4:00}.txt", args)); FileAppender newAppender = new FileAppender { File = this.FileName, Layout = layout, LockingModel = new FileAppender.MinimalLock() }; LevelRangeFilter filter = new LevelRangeFilter { LevelMin = this.level_0, LevelMax = this.level_1, AcceptOnMatch = true }; newAppender.AddFilter(filter); layout.ActivateOptions(); newAppender.ActivateOptions(); AsyncAppender appender2 = new AsyncAppender(); appender2.AddAppender(newAppender); appender2.ActivateOptions(); log4net.Repository.Hierarchy.Hierarchy hierarchy1 = (log4net.Repository.Hierarchy.Hierarchy)LogManager.CreateRepository(this.string_0); hierarchy1.Root.AddAppender(appender2); hierarchy1.Configured = true; }
public static ILog GetCustomLogger(string loggerName, string category = null, bool additivity = false) { return(loggerContainer.GetOrAdd(loggerName, delegate(string name) { RollingFileAppender newAppender = null; ReadParamAppender appender = null; if (appenderContainer.ContainsKey(loggerName)) { appender = appenderContainer[loggerName]; newAppender = GetNewFileApender(loggerName, string.IsNullOrEmpty(appender.File) ? GetFile(category, loggerName) : appender.File, appender.MaxSizeRollBackups, appender.AppendToFile, true, appender.MaximumFileSize, RollingFileAppender.RollingMode.Composite, appender.DatePattern, appender.LayoutPattern); } else { newAppender = GetNewFileApender(loggerName, GetFile(category, loggerName), MAX_SIZE_ROLL_BACKUPS, true, true, MAXIMUM_FILE_SIZE, RollingFileAppender.RollingMode.Composite, DATE_PATTERN, LAYOUT_PATTERN); } log4net.Repository.Hierarchy.Hierarchy repository = (log4net.Repository.Hierarchy.Hierarchy)LogManager.GetRepository(); Logger logger = repository.LoggerFactory.CreateLogger(repository, loggerName); logger.Hierarchy = repository; logger.Parent = repository.Root; logger.Level = GetLoggerLevel(appender == null ? LEVEL : appender.Level); logger.Additivity = additivity; logger.AddAppender(newAppender); logger.Repository.Configured = true; return new LogImpl(logger); })); }
/// <summary> /// Init log4net memoryAppender /// http://dhvik.blogspot.com/2008/08/adding-appender-to-log4net-in-runtime.html /// </summary> void InitLogger() { //First create and configure the appender this.memoryAppender = new MemoryAppender(); this.memoryAppender.Name = this.GetType().Name + "MemoryAppender"; PatternLayout layout = new PatternLayout(); layout.ConversionPattern = "%date [%thread] %-5level %logger - %message%newline"; layout.ActivateOptions(); this.memoryAppender.Layout = layout; //Notify the appender on the configuration changes this.memoryAppender.ActivateOptions(); //Get the logger repository hierarchy. this.repository = (Hierarchy)LogManager.GetRepository(); //and add the appender to the root level //of the logging hierarchy this.repository.Root.AddAppender(memoryAppender); //configure the logging at the root. //this.repository.Root.Level = Level.Info; //mark repository as configured and notify that is has changed. this.repository.Configured = true; this.repository.RaiseConfigurationChanged(EventArgs.Empty); this.msgWriter = new StringWriter(); }
/// <summary> /// Test the ability to disable a level of message /// </summary> [Test] public void TestDisable1() { CountingAppender caRoot = new CountingAppender(); Logger root = ((log4net.Repository.Hierarchy.Hierarchy)LogManager.GetRepository()).Root; root.AddAppender(caRoot); log4net.Repository.Hierarchy.Hierarchy h = ((log4net.Repository.Hierarchy.Hierarchy)LogManager.GetRepository()); h.Threshold = Level.Info; h.Configured = true; Assert.AreEqual(caRoot.Counter, 0); root.Log(Level.Debug, MSG, null); Assert.AreEqual(caRoot.Counter, 0); root.Log(Level.Info, MSG, null); Assert.AreEqual(caRoot.Counter, 1); root.Log(Level.Warn, MSG, null); Assert.AreEqual(caRoot.Counter, 2); root.Log(Level.Warn, MSG, null); Assert.AreEqual(caRoot.Counter, 3); h.Threshold = Level.Warn; root.Log(Level.Debug, MSG, null); Assert.AreEqual(caRoot.Counter, 3); root.Log(Level.Info, MSG, null); Assert.AreEqual(caRoot.Counter, 3); root.Log(Level.Warn, MSG, null); Assert.AreEqual(caRoot.Counter, 4); root.Log(Level.Error, MSG, null); Assert.AreEqual(caRoot.Counter, 5); root.Log(Level.Error, MSG, null); Assert.AreEqual(caRoot.Counter, 6); h.Threshold = Level.Off; root.Log(Level.Debug, MSG, null); Assert.AreEqual(caRoot.Counter, 6); root.Log(Level.Info, MSG, null); Assert.AreEqual(caRoot.Counter, 6); root.Log(Level.Warn, MSG, null); Assert.AreEqual(caRoot.Counter, 6); root.Log(Level.Error, MSG, null); Assert.AreEqual(caRoot.Counter, 6); root.Log(Level.Fatal, MSG, null); Assert.AreEqual(caRoot.Counter, 6); root.Log(Level.Fatal, MSG, null); Assert.AreEqual(caRoot.Counter, 6); }
private void SetupLog4Net() { var fileName = Path.Combine(Directory.GetCurrentDirectory(), @"..\Live\FileLogger.txt"); Console.WriteLine("Logging to {0}", fileName); _hierarchy = (Hierarchy) LogManager.GetRepository(); var patternLayout = new PatternLayout { ConversionPattern = "%date [%thread] %-5level %logger - %message%newline" }; patternLayout.ActivateOptions(); var roller = new FileAppender { AppendToFile = true, File = @"..\Live\FileLogger.txt", Layout = patternLayout, }; roller.ActivateOptions(); _hierarchy.Root.AddAppender(roller); _hierarchy.Root.Level = Level.Debug; _hierarchy.Configured = true; }
public async void Configure(IBlazorApplicationBuilder app) { app.AddComponent <App>("app"); log4net.Repository.Hierarchy.Hierarchy hierarchy = (Hierarchy)log4net.LogManager.GetRepository(Assembly.GetAssembly(typeof(Startup))); PatternLayout patternLayout = new PatternLayout(); patternLayout.ConversionPattern = "%date [%thread] %-5level %logger - %message%newline"; patternLayout.ActivateOptions(); var cca = new ConsoleAppender(); cca.Layout = patternLayout; cca.ActivateOptions(); hierarchy.Root.AddAppender(cca); hierarchy.Root.Level = Level.Debug; hierarchy.Configured = true; log.Info("test"); log.Info("Configure Done"); }
static void Main(string[] args) { if (args.Length == 0) { Console.WriteLine( "Usage: ParameterMetaDataGenerator.exe \"ArduCopter\\Parameters.cpp;ArduPlane\\Parameters.cpp;APMrover2\\Parameters.cpp\" output.xml"); return; } log4net.Repository.Hierarchy.Hierarchy hierarchy = (Hierarchy)log4net.LogManager.GetRepository(Assembly.GetAssembly(typeof(Program))); PatternLayout patternLayout = new PatternLayout(); patternLayout.ConversionPattern = "%date [%thread] %-5level %logger - %message%newline"; patternLayout.ActivateOptions(); var cca = new ConsoleAppender(); cca.Layout = patternLayout; cca.ActivateOptions(); hierarchy.Root.AddAppender(cca); hierarchy.Root.Level = Level.Debug; hierarchy.Configured = true; ParameterMetaDataParser.GetParameterInformation(args[0], args[1]); }
public Logger(string fileName) { _hierarchy = (Hierarchy) LogManager.GetRepository(); var patternLayout = new PatternLayout { ConversionPattern = "%date [%thread] %-5level %logger - %message%newline" }; patternLayout.ActivateOptions(); var roller = new FileAppender { AppendToFile = true, File = fileName, 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; }
public App() { InitializeComponent(); AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; log4net.Repository.Hierarchy.Hierarchy hierarchy = (Hierarchy)log4net.LogManager.GetRepository(Assembly.GetAssembly(typeof(App))); PatternLayout patternLayout = new PatternLayout(); patternLayout.ConversionPattern = "[%thread] %-5level %logger - %message"; patternLayout.ActivateOptions(); var cca = new ConsoleAppender(); cca.Layout = patternLayout; cca.ActivateOptions(); hierarchy.Root.AddAppender(cca); hierarchy.Root.Level = Level.Debug; hierarchy.Configured = true; MainPage = new MainPage(); }
/// <summary> /// Warning: this is not tread-safe, so only call this at startup or at a time that you are sure your /// process is not performing any logging! /// </summary> /// <param name="filePath">The path to the log file.</param> /// <param name="sourceLevels">The lowest log level to log.</param> public static void SetLogFilePath(string filePath, SourceLevels sourceLevels) { if (!Path.IsPathRooted(filePath)) { filePath = Path.Combine(ArgusTVLogFolder, filePath); } Level level = Level.Debug; if (_sourceLevels == SourceLevels.Information) { level = Level.Info; } else if (_sourceLevels == SourceLevels.Warning) { level = Level.Warn; } else if (_sourceLevels == SourceLevels.Error) { level = Level.Error; } else if (_sourceLevels == SourceLevels.Critical) { level = Level.Fatal; } _sourceLevels = sourceLevels; log4Hierarchy.Hierarchy hierarchy = (log4Hierarchy.Hierarchy)LogManager.GetAllRepositories().FirstOrDefault(r => r.Name == _argusTV); if (hierarchy == null) { hierarchy = (log4Hierarchy.Hierarchy)LogManager.CreateRepository(_argusTV); } hierarchy.Root.RemoveAllAppenders(); RollingFileAppender roller = new RollingFileAppender(); PatternLayout patternLayout = new PatternLayout(); patternLayout.ConversionPattern = "%date [%-5level][%thread]: %message%newline"; patternLayout.ActivateOptions(); roller.Layout = patternLayout; roller.AppendToFile = true; roller.RollingStyle = RollingFileAppender.RollingMode.Size; roller.MaxSizeRollBackups = 4; roller.MaximumFileSize = "1000KB"; roller.StaticLogFileName = true; roller.File = filePath; roller.ActivateOptions(); roller.AddFilter(new log4net.Filter.LevelRangeFilter() { LevelMin = level, LevelMax = Level.Fatal }); log4net.Config.BasicConfigurator.Configure(hierarchy, roller); log4Hierarchy.Logger coreLogger = hierarchy.GetLogger(_argusTV) as log4Hierarchy.Logger; coreLogger.Level = level; _log = LogManager.GetLogger(hierarchy.Name, _argusTV); }
public MainPage() { this.InitializeComponent(); Console.WriteLine("MainPage ctor"); Task.Run(() => start()); log4net.Repository.Hierarchy.Hierarchy hierarchy = (Hierarchy)log4net.LogManager.GetRepository(Assembly.GetAssembly(typeof(App))); var patternLayout = new PatternLayout(); patternLayout.ConversionPattern = "[%thread] %-5level %logger %memory - %message"; //patternLayout.AddConverter(new ConverterInfo() {Name = "memory", Type = typeof(PatternConverter)}); patternLayout.ActivateOptions(); var cca = new ConsoleAppender(); cca.Layout = patternLayout; cca.ActivateOptions(); hierarchy.Root.AddAppender(cca); hierarchy.Root.Level = Level.Debug; hierarchy.Configured = true; Console.WriteLine("MainPage ctor end"); //var th = new Thread(start); //th.Start(); }
private static void CreateLogger(FileAppender fileAppender, string loggerName) { log4net.Repository.Hierarchy.Hierarchy hierarchy = (log4net.Repository.Hierarchy.Hierarchy)log4net.LogManager.GetLoggerRepository(); log4net.Repository.Hierarchy.Logger logger = (log4net.Repository.Hierarchy.Logger)hierarchy.GetLogger(APPENDER_NAME); logger.RemoveAllAppenders(); logger.AddAppender(fileAppender); hierarchy.Configured = true; }
// type constructor static Log4NetLogger() { // configure internal structures from xml XmlConfigurator.Configure(new FileInfo(FILE_CONFIG_NAME)); // obtain logger and hierarchy with appenders s_databaseLog = LogManager.GetLogger(LOGGER_NAME); s_appenderHierarchy = (Hierarchy)LogManager.GetLoggerRepository(); }
private void CreateDefaultMemoryAppender() { _memoryAppender = new RollingMemoryAppender(); _memoryAppender.Name = "DeveloperToolsLogViewer"; _memoryAppender.ActivateOptions(); log4net.Repository.Hierarchy.Hierarchy repository = LogManager.GetRepository() as Hierarchy; repository.Root.AddAppender(_memoryAppender); repository.Root.Level = Level.All; repository.Configured = true; repository.RaiseConfigurationChanged(EventArgs.Empty); }
private WebServiceAppender AddAppender(Hierarchy hierarchy) { var webserviceLayout = new PatternLayout { ConversionPattern = "%P{UserId} %P{Identifier} %P{Session} %-5p %m" }; webserviceLayout.ActivateOptions(); var appender = new WebServiceAppender(EndpointManager) { Layout = webserviceLayout, Threshold = Level.Info }; appender.ActivateOptions(); hierarchy.Root.AddAppender(appender); return appender; }
private void Create_HierarchyLogger() { if (_isconfigured == false) { _HierarchyLogger = (Hierarchy)LogManager.GetRepository(); // Remove any other appenders _HierarchyLogger.Root.RemoveAllAppenders(); // define some basic settings for the root _HierarchyLogger.Root.Level = Level.All; _HierarchyLogger.Configured = true; } }
/// <summary> /// Tests the chained level for a hierarchy /// </summary> [Test] public void TestHierarchy1() { log4net.Repository.Hierarchy.Hierarchy h = new log4net.Repository.Hierarchy.Hierarchy(); h.Root.Level = Level.Error; Logger a0 = h.GetLogger("a") as Logger; Assert.AreEqual("a", a0.Name); Assert.IsNull(a0.Level); Assert.AreSame(Level.Error, a0.EffectiveLevel); Logger a1 = h.GetLogger("a") as Logger; Assert.AreSame(a0, a1); }
private static void AlterLogPath(this log4net.Repository.ILoggerRepository repo, string newPath, string directory = "") { log4net.Repository.Hierarchy.Hierarchy h = (log4net.Repository.Hierarchy.Hierarchy)repo; foreach (log4net.Appender.IAppender a in h.Root.Appenders) { if (a is log4net.Appender.FileAppender) { var fa = (log4net.Appender.FileAppender)a; var fileName = Path.GetFileName(fa.File); fa.File = newPath + (String.IsNullOrEmpty(directory)?"":(directory + Path.DirectorySeparatorChar.ToString())); // edit: filename is attached after next line automatically. fa.ActivateOptions(); break; } } }
public void TestFirstLog4Net() { log4net.ILog log = log4net.LogManager.GetLogger(this.GetType()); log4net.Config.XmlConfigurator.Configure(); log4net.Repository.Hierarchy.Hierarchy h = (Hierarchy)log4net.LogManager.GetRepository(); var adoAppenders = h.GetAppenders().OfType <AdoNetAppender>(); //adoAppender.ConnectionString = "Data Source=XE;User ID=APPLICATIONDB;Password=password"; //adoAppender.CommandText = "INSERT INTO LOG4NET (LOG_ID, LOG_DATE, LOG_LEVEL, LOG_IDENTITY, LOG_MESSAGE, LOG_EXCEPTION) VALUES (LOG4NET_SEQ.nextval, :log_date, :log_level, :log_identity, :log_message, :log_exception)"; foreach (var appender in adoAppenders) { appender.ConnectionString = ConfigurationManager.ConnectionStrings["OraDB_Log"].ConnectionString; appender.ActivateOptions(); } log.Info("hello world!"); }
public void TestHierarchy() { log4net.Repository.Hierarchy.Hierarchy h = new log4net.Repository.Hierarchy.Hierarchy(); h.Root.Level = Level.Error; //获得一个记录器(如果不存在,则创建并返回) Logger a0 = (Logger)h.GetLogger("a"); Assert.AreEqual("a", a0.Name); Assert.IsNull(a0.Level); Assert.AreSame(Level.Error, a0.EffectiveLevel); //获得之前创建的记录器 Logger a1 = (Logger)h.GetLogger("a"); Assert.AreSame(a0, a1); }
//========================================================= // PRIVATE //========================================================= protected InsideWordWebLog() { _logger = LogManager.GetLogger("InsideWordWeb"); XmlConfigurator.Configure(); _hier = _logger.Logger.Repository as Hierarchy; _root = _hier.Root as RootLogger; // Funky line, but used to normalize the root, current logger // and all it's appenders to the same login threshold. IWThreshold = IWThreshold; IWSmtpThreshold = IWThreshold; _logger.Info("Logging initialized"); MaxBufferSize = 128; _buffer = new Dictionary<string, List<string>>(); _currentFlushWorker = new BackgroundWorker(); _currentFlushWorker.DoWork += DelegateFlushBuffer; _flushQueue = new Queue<string>(); }
public static ILog GetCustomLogger(string loggerName, string category = null, bool additivity = false) { return(loggerContainer.GetOrAdd(loggerName, delegate(string name) { RollingFileAppender newAppender = GetNewFileApender(loggerName, GetFile(category, loggerName), MAX_SIZE_ROLL_BACKUPS, true, true, MAXIMUM_FILE_SIZE, RollingFileAppender.RollingMode.Composite, DATE_PATTERN, LAYOUT_PATTERN); log4net.Repository.Hierarchy.Hierarchy repository = (log4net.Repository.Hierarchy.Hierarchy)LogManager.GetRepository(); Logger logger = repository.LoggerFactory.CreateLogger(repository, loggerName); logger.Hierarchy = repository; logger.Parent = repository.Root; logger.Level = GetLoggerLevel(LEVEL); logger.Additivity = additivity; logger.AddAppender(newAppender); logger.Repository.Configured = true; return new LogImpl(logger); })); }
/// <summary> /// The add console appender. /// </summary> /// <param name="hierarchy"> /// The hierarchy. /// </param> /// <param name="layout"> /// The layout. /// </param> private static void AddConsoleAppender(Hierarchy hierarchy, ILayout layout) { var consoleAppender = new ColoredConsoleAppender { Layout = layout }; consoleAppender.AddMapping( new ColoredConsoleAppender.LevelColors { Level = Level.Fatal, BackColor = ColoredConsoleAppender.Colors.Purple | ColoredConsoleAppender.Colors.HighIntensity, ForeColor = ColoredConsoleAppender.Colors.White }); consoleAppender.AddMapping( new ColoredConsoleAppender.LevelColors { Level = Level.Error, ForeColor = ColoredConsoleAppender.Colors.Red | ColoredConsoleAppender.Colors.HighIntensity }); consoleAppender.AddMapping( new ColoredConsoleAppender.LevelColors { Level = Level.Warn, ForeColor = ColoredConsoleAppender.Colors.Yellow | ColoredConsoleAppender.Colors.HighIntensity }); consoleAppender.AddMapping( new ColoredConsoleAppender.LevelColors { Level = Level.Info, ForeColor = ColoredConsoleAppender.Colors.White | ColoredConsoleAppender.Colors.HighIntensity }); consoleAppender.AddMapping( new ColoredConsoleAppender.LevelColors { Level = Level.Debug, ForeColor = ColoredConsoleAppender.Colors.White }); consoleAppender.AddFilter( new LevelRangeFilter { AcceptOnMatch = true, LevelMin = AppUtil.IsDebugBuild ? Level.Debug : Level.Info, LevelMax = Level.Fatal }); consoleAppender.ActivateOptions(); hierarchy.Root.AddAppender(consoleAppender); }
/// <summary> /// Initializes <see cref="Common.Logging.LogManager"/> with a <see cref="Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter"/> after /// having configured log4net to emit low levels logs. /// </summary> /// <param name="appLogDirectory">The directory for low leveel logs.</param> /// <param name="dumpToConsole">True to log all traces into the console.</param> public static void Initialize( string appLogDirectory, bool dumpToConsole ) { string logPattern = "%date [%thread] %-5level %logger - %message%newline"; _appLogDirectory = appLogDirectory; if( !Directory.Exists( appLogDirectory ) ) Directory.CreateDirectory( appLogDirectory ); _hierarchy = (Hierarchy)log4net.LogManager.GetRepository(); PatternLayout patternLayout = new PatternLayout(); patternLayout.ConversionPattern = logPattern; patternLayout.ActivateOptions(); if( dumpToConsole ) { ConsoleAppender console = new ConsoleAppender(); console.Layout = patternLayout; console.ActivateOptions(); console.Threshold = Level.All; _hierarchy.Root.AddAppender( console ); } _roller = new RollingFileAppender(); _roller.Layout = patternLayout; _roller.AppendToFile = true; _roller.RollingStyle = RollingFileAppender.RollingMode.Size; _roller.MaxSizeRollBackups = 4; _roller.MaximumFileSize = "100KB"; _roller.StaticLogFileName = true; _roller.File = Path.Combine( _appLogDirectory, "LowLevel.log" ); _roller.ActivateOptions(); _hierarchy.Root.AddAppender( _roller ); _hierarchy.Configured = true; NameValueCollection properties = new NameValueCollection(); properties["configType"] = "EXTERNAL"; Common.Logging.LogManager.Adapter = new Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter( properties ); // Registers to inject last application logs into crash logs. AppRecoveryManager.ApplicationCrashed += new System.EventHandler<ApplicationCrashedEventArgs>( OnApplicationCrash ); _initialized = true; }
public App() { InitializeComponent(); log4net.Repository.Hierarchy.Hierarchy hierarchy = (Hierarchy)log4net.LogManager.GetRepository(Assembly.GetAssembly(typeof(App))); var patternLayout = new PatternLayout(); patternLayout.ConversionPattern = "[%thread] %-5level %logger %memory - %message"; patternLayout.AddConverter(new ConverterInfo() { Name = "memory", Type = typeof(MemoryConverterInfo) }); patternLayout.ActivateOptions(); var cca = new ConsoleAppender(); cca.Layout = patternLayout; cca.ActivateOptions(); hierarchy.Root.AddAppender(cca); hierarchy.Root.Level = Level.Debug; hierarchy.Configured = true; { var config = new NLog.Config.LoggingConfiguration(); // Targets where to log to: File and Console var logconsole = new NLog.Targets.ConsoleTarget("logconsole"); // Rules for mapping loggers to targets // config.AddRule(LogLevel.Warn, LogLevel.Fatal, logconsole); // Apply config NLog.LogManager.Configuration = config; } MainPage = new MainPage(); }
static void PrepareLoggerLevel(ILoggerRepository repository, string domain, string level) { repository.Threshold = repository.LevelMap[level]; log4net.Repository.Hierarchy.Hierarchy hier = (log4net.Repository.Hierarchy.Hierarchy)repository; log4net.Core.ILogger[] loggers = hier.GetCurrentLoggers(); foreach (log4net.Core.ILogger logger in loggers) { Console.WriteLine(logger.Name); ((log4net.Repository.Hierarchy.Logger)logger).Level = hier.LevelMap[level]; if (Environment.UserInteractive) { ((log4net.Repository.Hierarchy.Logger)logger).RemoveAllAppenders(); ColoredConsoleAppender appender = CreateColoredConsoleAppender(domain); ((log4net.Repository.Hierarchy.Logger)logger).AddAppender(appender); (appender.Layout as SyslogLayout).ActivateOptions(); appender.ActivateOptions(); } } hier.RaiseConfigurationChanged(EventArgs.Empty); }
public MainPage() { this.InitializeComponent(); Console.WriteLine("MainPage ctor"); SKCanvasForms.PaintSurface += OnPaintSurface; SKCanvasForms.PointerMoved += SKCanvasForms_PointerMoved; //Task.Run(() => start()); log4net.Repository.Hierarchy.Hierarchy hierarchy = (Hierarchy)log4net.LogManager.GetRepository(Assembly.GetAssembly(typeof(App))); var patternLayout = new PatternLayout(); patternLayout.ConversionPattern = "[%thread] %-5level %logger %memory - %message\n"; //patternLayout.AddConverter(new ConverterInfo() {Name = "memory", Type = typeof(PatternConverter)}); patternLayout.ActivateOptions(); var cca = new ConsoleAppender(); cca.Layout = patternLayout; cca.ActivateOptions(); hierarchy.Root.AddAppender(cca); hierarchy.Root.Level = Level.Debug; hierarchy.Configured = true; Console.WriteLine("MainPage ctor end"); //var th = new Thread(start); //th.Start(); SerialPort.DefaultType = (self, s, i) => { return(null); }; start(); pollDraw(); }
// check if the logging system uses UnityLog4NetAppender private bool CheckForUnityAppender() { log4net.Repository.Hierarchy.Hierarchy hierarchy = log4net.LogManager.GetRepository() as log4net.Repository.Hierarchy.Hierarchy; if (hierarchy.Root.Appenders.Count > 0) { foreach (log4net.Appender.IAppender appender in hierarchy.Root.Appenders) { if (appender is UnityLog4NetAppender) { if (!LogSDKDebug) { (appender as UnityLog4NetAppender).Threshold = log4net.Core.Level.Info; } return(true); } } return(false); } else { // if we got here the is no configuration for the logger hierarchy.Root.RemoveAllAppenders(); /*Remove any other appenders*/ UnityLog4NetAppender unityAppender = new UnityLog4NetAppender(); log4net.Layout.PatternLayout pl = new log4net.Layout.PatternLayout(); pl.ConversionPattern = "%m"; pl.ActivateOptions(); unityAppender.Layout = pl; if (!LogSDKDebug) { (unityAppender as UnityLog4NetAppender).Threshold = log4net.Core.Level.Info; } unityAppender.ActivateOptions(); log4net.Config.BasicConfigurator.Configure(unityAppender); return(true); } }
public static async Task Main(string[] args) { var builder = WebAssemblyHostBuilder.CreateDefault(args); builder.RootComponents.Add <App>("app"); builder.Services.AddTransient(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) }); builder.Services.AddFileReaderService(options => options.UseWasmSharedBuffer = true); builder.Services.AddStorage(); builder.Services.AddSpeechSynthesis(); builder.Services.AddScoped <IIndexedDbFactory, IndexedDbFactory>(); builder.Services.AddWorkerFactory(); builder.Services.AddToaster(config => { //example customizations config.PositionClass = Defaults.Classes.Position.TopRight; config.PreventDuplicates = true; config.NewestOnTop = true; }); { //bool result1 = WebRequest.RegisterPrefix("http://", new Startup.FakeRequestFactory()); //Console.WriteLine("webrequestmod " + result1); //bool result2 = WebRequest.RegisterPrefix("https://", new Startup.FakeRequestFactory()); //Console.WriteLine("webrequestmod " + result2); log4net.Repository.Hierarchy.Hierarchy hierarchy = (Hierarchy)log4net.LogManager.GetRepository(Assembly.GetAssembly(typeof(Startup))); PatternLayout patternLayout = new PatternLayout(); patternLayout.ConversionPattern = "%date [%thread] %-5level %logger - %message%newline"; patternLayout.ActivateOptions(); var cca = new ConsoleAppender(); cca.Layout = patternLayout; cca.ActivateOptions(); hierarchy.Root.AddAppender(cca); hierarchy.Root.Level = Level.Debug; hierarchy.Configured = true; log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); log.Info("test"); log.Info("Configure Done"); //System.Net.WebRequest.get_InternalDefaultWebProxy //WebRequest.DefaultWebProxy = GlobalProxySelection.GetEmptyWebProxy(); Directory.CreateDirectory(@"/home/web_user/Desktop"); BinaryLog.onFlightMode += (firmware, modeno) => { try { if (firmware == "") { return(null); } var modes = Common.getModesList((Firmwares)Enum.Parse(typeof(Firmwares), firmware)); string currentmode = null; foreach (var mode in modes) { if (mode.Key == modeno) { currentmode = mode.Value; break; } } return(currentmode); } catch { return(null); } }; CustomMessageBox.ShowEvent += (text, caption, buttons, icon, yestext, notext) => { Console.WriteLine("CustomMessageBox " + caption + " " + text); return(CustomMessageBox.DialogResult.OK); }; MissionPlanner.Utilities.Download.RequestModification += Download_RequestModification; } await builder.Build().RunAsync(); }
/// <summary> /// Tests the chained level for a hierarchy /// </summary> [Test] public void TestHierarchy1() { Hierarchy h = new Hierarchy(); h.Root.Level = Level.ERROR; Logger a0 = h.GetLogger("a") as Logger; Assertion.AssertEquals("a", a0.Name); Assertion.AssertNull(a0.Level); Assertion.AssertSame(Level.ERROR, a0.EffectiveLevel); Logger a1 = h.GetLogger("a") as Logger; Assertion.AssertSame(a0, a1); }
static void Main(string[] args) { log4net.Repository.Hierarchy.Hierarchy hierarchy = (Hierarchy)log4net.LogManager.GetRepository(Assembly.GetAssembly(typeof(Program))); PatternLayout patternLayout = new PatternLayout(); patternLayout.ConversionPattern = "%date [%thread] %-5level %logger - %message%newline"; patternLayout.ActivateOptions(); var cca = new ConsoleAppender(); cca.Layout = patternLayout; cca.ActivateOptions(); hierarchy.Root.AddAppender(cca); hierarchy.Root.Level = Level.Debug; hierarchy.Configured = true; if (false) { var resp = "https://api.github.com/repos/ardupilot/ardupilot/git/refs/tags" .WithHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36") .AllowAnyHttpStatus() .GetAsync().Result; var tags = resp.GetJsonListAsync().Result; foreach (var tag in tags) { var tagdict = (IDictionary <String, Object>)tag; var refpath = tagdict["ref"].ToString(); if (refpath.Contains("ArduPlane") || refpath.Contains("Copter") || refpath.Contains("Rover") || refpath.Contains("APMrover2") || refpath.Contains("ArduSub") || refpath.Contains("AntennaTracker")) { var taginfo = (IDictionary <String, Object>)((string)tagdict["url"]) .WithHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36") .GetJsonAsync().Result; var sha = ((IDictionary <String, Object>)taginfo["object"])["sha"].ToString(); var refname = ((string)taginfo["ref"]).Replace("refs/tags/", ""); var paramfile = ""; if (refname.Contains("Copter")) { paramfile = "ArduCopter/Parameters.pde;ArduCopter/Parameters.cpp"; } if (refname.Contains("ArduPlane")) { paramfile = "ArduPlane/Parameters.pde;ArduPlane/Parameters.cpp"; } if (refname.Contains("ArduSub")) { paramfile = "ArduSub/Parameters.pde;ArduSub/Parameters.cpp"; } if (refname.Contains("Rover")) { paramfile = "Rover/Parameters.pde;Rover/Parameters.cpp"; } if (refname.Contains("APMrover2")) { paramfile = "APMrover2/Parameters.pde;APMrover2/Parameters.cpp"; } if (refname.Contains("AntennaTracker")) { paramfile = "AntennaTracker/Parameters.pde;AntennaTracker/Parameters.cpp"; } if (paramfile == "") { continue; } var XMLFileName = String.Format("{0}{1}", Settings.GetUserDataDirectory(), refname + ".xml"); if (File.Exists(XMLFileName)) { continue; } ParameterMetaDataParser.GetParameterInformation( paramfile.Split(';') .Select(a => { a = a.Trim(); return("https://raw.github.com/ardupilot/ardupilot/" + sha + "/" + a + ";"); }).Aggregate("", (a, b) => a + b) , refname + ".xml"); } } } if (args.Length == 1) { Console.WriteLine("needs ot be started inside the git repo"); var proc = new System.Diagnostics.Process { StartInfo = new System.Diagnostics.ProcessStartInfo { FileName = "git", Arguments = "tag", UseShellExecute = false, RedirectStandardOutput = true, CreateNoWindow = true } }; proc.Start(); var resp = proc.StandardOutput.ReadToEnd(); var tags = resp.Split('\n'); foreach (var tag in tags) { var refpath = tag; if (refpath.Contains("ArduPlane") || refpath.Contains("Copter") || refpath.Contains("Rover") || refpath.Contains("APMrover2") || refpath.Contains("ArduSub") || refpath.Contains("AntennaTracker")) { if (!Regex.IsMatch(refpath, @"\.[0-9]+$")) { continue; } var refname = tag; var paramfile = ""; if (refname.Contains("Copter")) { paramfile = "ArduCopter/Parameters.pde;ArduCopter/Parameters.cpp"; } if (refname.Contains("ArduPlane")) { paramfile = "ArduPlane/Parameters.pde;ArduPlane/Parameters.cpp"; } if (refname.Contains("ArduSub")) { paramfile = "ArduSub/Parameters.pde;ArduSub/Parameters.cpp"; } if (refname.Contains("Rover") || refname.Contains("APMrover2")) { paramfile = "Rover/Parameters.pde;Rover/Parameters.cpp;APMrover2/Parameters.pde;APMrover2/Parameters.cpp"; } if (refname.Contains("AntennaTracker")) { paramfile = "AntennaTracker/Parameters.pde;AntennaTracker/Parameters.cpp"; } if (paramfile == "") { continue; } var XMLFileName = String.Format("{0}{1}", Settings.GetUserDataDirectory(), refname + ".xml"); if (File.Exists(XMLFileName)) { continue; } var proc2 = new System.Diagnostics.Process() { StartInfo = new System.Diagnostics.ProcessStartInfo("git", "reset --hard " + tag) { CreateNoWindow = true, UseShellExecute = false } }; proc2.Start(); proc2.WaitForExit(); ParameterMetaDataParser.GetParameterInformation( paramfile.Split(';') .Select(a => { a = a.Trim(); return(Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar + a + ";"); }).Aggregate("", (a, b) => a + b) , refname + ".xml"); } } return; } if (args.Length == 0) { Console.WriteLine( "Usage: ParameterMetaDataGenerator.exe \"ArduCopter\\Parameters.cpp;ArduPlane\\Parameters.cpp;APMrover2\\Parameters.cpp\" output.xml"); return; } ParameterMetaDataParser.GetParameterInformation(args[0], args[1]); }
public SyncServiceLogAppender(string fileLocation, long storeLocationID) { log4net.Repository.Hierarchy.Hierarchy repository = (log4net.Repository.Hierarchy.Hierarchy)log4net.LogManager.GetRepository(); if (fileLocation != "") { LoggerSimple.WriteMessage("Creating logger...." + fileLocation); var appenders = repository.GetAppenders(); if (appenders.FirstOrDefault(i => i.Name == "ASyncServiceLogAppender-" + storeLocationID) != null) { return; } SyncServiceFileAppender originalAppender = appenders.FirstOrDefault(i => i.Name == "SyncServiceLogAppender-0") as SyncServiceFileAppender; //(appenders[0] as SyncServiceFileAppender); SyncServiceFileAppender fileAppender = new SyncServiceFileAppender(); fileAppender.Name = "ASyncServiceLogAppender-" + storeLocationID; fileAppender.File = fileLocation; fileAppender.AppendToFile = true; fileAppender.MaxSizeRollBackups = originalAppender.MaxSizeRollBackups; fileAppender.MaximumFileSize = originalAppender.MaximumFileSize; fileAppender.RollingStyle = originalAppender.RollingStyle; fileAppender.MaximumFileSize = originalAppender.MaximumFileSize; fileAppender.CountDirection = originalAppender.CountDirection; fileAppender.DatePattern = originalAppender.DatePattern; fileAppender.ImmediateFlush = originalAppender.ImmediateFlush; fileAppender.MaxFileSize = originalAppender.MaxFileSize; fileAppender.StaticLogFileName = false; fileAppender.Threshold = log4net.Core.Level.All; fileAppender.Layout = originalAppender.Layout; fileAppender.LockingModel = new FileAppender.MinimalLock(); fileAppender.ActivateOptions(); fileAppender.FilePath = fileLocation; log4net.Repository.Hierarchy.Logger logger = (log4net.Repository.Hierarchy.Logger)repository.GetLogger("ASyncServiceLogAppender-" + storeLocationID); logger.AddAppender(fileAppender); LoggerSimple.WriteMessage("Logger Created..." + storeLocationID); Writer = LogManager.GetLogger("ASyncServiceLogAppender-" + storeLocationID); } else { Writer = LogManager.GetLogger("SyncServiceLogAppender-" + storeLocationID); } }
/// <summary> /// Construct the configurator for a hierarchy /// </summary> /// <param name="hierarchy">The hierarchy to build.</param> /// <remarks> /// <para> /// Initializes a new instance of the <see cref="XmlHierarchyConfigurator" /> class /// with the specified <see cref="Hierarchy" />. /// </para> /// </remarks> public XmlHierarchyConfigurator(Autofac.IComponentContext context, Hierarchy hierarchy) { m_context = context; m_hierarchy = hierarchy; m_appenderBag = new Hashtable(); }
//IBlazorApplicationBuilder //IComponentsApplicationBuilder public void Configure(IComponentsApplicationBuilder app) { app.AddComponent <App>("app"); log4net.Repository.Hierarchy.Hierarchy hierarchy = (Hierarchy)log4net.LogManager.GetRepository(Assembly.GetAssembly(typeof(Startup))); PatternLayout patternLayout = new PatternLayout(); patternLayout.ConversionPattern = "%date [%thread] %-5level %logger - %message%newline"; patternLayout.ActivateOptions(); var cca = new ConsoleAppender(); cca.Layout = patternLayout; cca.ActivateOptions(); hierarchy.Root.AddAppender(cca); hierarchy.Root.Level = Level.Debug; hierarchy.Configured = true; log.Info("test"); log.Info("Configure Done"); BinaryLog.onFlightMode += (firmware, modeno) => { try { if (firmware == "") { return(null); } var modes = Common.getModesList((Firmwares)Enum.Parse(typeof(Firmwares), firmware)); string currentmode = null; foreach (var mode in modes) { if (mode.Key == modeno) { currentmode = mode.Value; break; } } return(currentmode); } catch { return(null); } }; CustomMessageBox.ShowEvent += (text, caption, buttons, icon, yestext, notext) => { Console.WriteLine("CustomMessageBox " + caption + " " + text); return(CustomMessageBox.DialogResult.OK); }; }
/// <summary> /// The add file appender. /// </summary> /// <param name="hierarchy"> /// The hierarchy. /// </param> /// <param name="layout"> /// The layout. /// </param> private static void AddFileAppender(Hierarchy hierarchy, ILayout layout) { string logFileName = AppUtil.GetLocalDataPath("Logs\\" + AppUtil.EntryModuleName); string actualLogFileName = logFileName; int tryCount = 0; while (IOUtils.IsFileLocked(actualLogFileName + LOG_EXT)) { if (tryCount++ == 0) { logFileName = actualLogFileName += DateTime.Now.ToString("_yyyyMMdd"); } else { actualLogFileName = logFileName + "_" + (tryCount - 1); } } string targetFile = actualLogFileName + LOG_EXT; Console.WriteLine("Initializing log file: " + targetFile); var fileAppender = new RollingFileAppender { Layout = layout, File = targetFile, AppendToFile = true, RollingStyle = RollingFileAppender.RollingMode.Size, MaxSizeRollBackups = 10, MaximumFileSize = "10MB", StaticLogFileName = true }; fileAppender.AddFilter( new LevelRangeFilter { AcceptOnMatch = true, LevelMin = AppUtil.IsDebugBuild ? Level.Debug : Level.Info, LevelMax = Level.Fatal }); fileAppender.ActivateOptions(); hierarchy.Root.AddAppender(fileAppender); }
/// <summary> /// Construct the configurator for a hierarchy /// </summary> /// <param name="hierarchy">The hierarchy to build.</param> /// <remarks> /// <para> /// Initializes a new instance of the <see cref="XmlHierarchyConfigurator" /> class /// with the specified <see cref="Hierarchy" />. /// </para> /// </remarks> public XmlHierarchyConfigurator(Hierarchy hierarchy) { m_hierarchy = hierarchy; m_appenderBag = new Hashtable(); }
private static void ConfigureRootLogger() { log4net.Repository.Hierarchy.Hierarchy repository = (log4net.Repository.Hierarchy.Hierarchy)LogManager.GetRepository(); repository.Root.RemoveAllAppenders(); repository.Root.Level = Level.All; }
static Logger \u200C([In] log4net.Repository.Hierarchy.Hierarchy obj0) { return(obj0.get_Root()); }
//IBlazorApplicationBuilder //IComponentsApplicationBuilder public void Configure(IComponentsApplicationBuilder app) { bool result1 = WebRequest.RegisterPrefix("http://", new FakeRequestFactory()); Console.WriteLine("webrequestmod " + result1); bool result2 = WebRequest.RegisterPrefix("https://", new FakeRequestFactory()); Console.WriteLine("webrequestmod " + result2); app.AddComponent <App>("app"); log4net.Repository.Hierarchy.Hierarchy hierarchy = (Hierarchy)log4net.LogManager.GetRepository(Assembly.GetAssembly(typeof(Startup))); PatternLayout patternLayout = new PatternLayout(); patternLayout.ConversionPattern = "%date [%thread] %-5level %logger - %message%newline"; patternLayout.ActivateOptions(); var cca = new ConsoleAppender(); cca.Layout = patternLayout; cca.ActivateOptions(); hierarchy.Root.AddAppender(cca); hierarchy.Root.Level = Level.Debug; hierarchy.Configured = true; log.Info("test"); log.Info("Configure Done"); //System.Net.WebRequest.get_InternalDefaultWebProxy //WebRequest.DefaultWebProxy = GlobalProxySelection.GetEmptyWebProxy(); Directory.CreateDirectory(@"/home/web_user/Desktop"); BinaryLog.onFlightMode += (firmware, modeno) => { try { if (firmware == "") { return(null); } var modes = Common.getModesList((Firmwares)Enum.Parse(typeof(Firmwares), firmware)); string currentmode = null; foreach (var mode in modes) { if (mode.Key == modeno) { currentmode = mode.Value; break; } } return(currentmode); } catch { return(null); } }; CustomMessageBox.ShowEvent += (text, caption, buttons, icon, yestext, notext) => { Console.WriteLine("CustomMessageBox " + caption + " " + text); return(CustomMessageBox.DialogResult.OK); }; }
public LogController(Hierarchy aHierarchy, Logger aRootLogger) { iHierarchy = aHierarchy; iRootLogger = aRootLogger; }
/// Constructor public ExceptionMessageRenderer() { _logHierarchy = LogManager.GetRepository() as Hierarchy; }
static void PrepareRootLoggerLevel(string level) { log4net.Repository.Hierarchy.Hierarchy h = (log4net.Repository.Hierarchy.Hierarchy)log4net.LogManager.GetRepository(); log4net.Repository.Hierarchy.Logger rootLogger = h.Root; rootLogger.Level = h.LevelMap[level]; }
private static void Setup(Hierarchy hierarchy) { PatternLayout patternLayout = new PatternLayout(); patternLayout.ConversionPattern = "%date [%thread] %-5level %logger - %message%newline"; patternLayout.ActivateOptions(); RollingFileAppender roller = new RollingFileAppender(); roller.AppendToFile = false; roller.File = @"Logs\EventLog.txt"; roller.Layout = patternLayout; roller.MaxSizeRollBackups = 5; roller.MaximumFileSize = "1GB"; roller.RollingStyle = RollingFileAppender.RollingMode.Size; roller.StaticLogFileName = true; roller.ActivateOptions(); hierarchy.Root.AddAppender(roller); MemoryAppender memory = new MemoryAppender(); memory.ActivateOptions(); hierarchy.Root.AddAppender(memory); }