/// <summary>Parameterized constructor. /// </summary> /// <param name="configFile"></param> public Log4NetLoggerFactory(string configFile) { var file = new FileInfo(configFile); if (!file.Exists) { file = new FileInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, configFile)); } if (file.Exists) { XmlConfigurator.ConfigureAndWatch(file); } else { BasicConfigurator.Configure(new ConsoleAppender { Layout = new PatternLayout() }); } }
public BasicAeronSpec() { BasicConfigurator.Configure(); _testDataSent = 0; _testDataReceived = 0; _testDataHandler = (data, length) => { _testDataReceived += length; }; const string channel = "aeron:ipc"; const int stream = 42; _aeron = Aeron.Connect(Defaults.GetNewSystemContext()); _source = new Source(_aeron, stream, channel, Defaults.BufferSize); _target = new Target(_aeron, stream, channel, Defaults.IdleStrategy, Defaults.FragmentLimit); _testByteArraySize = 1000; _rnd = new Random(); }
public MainForm() { InitializeComponent(); // Bindings contactList = new BindingList <Contact>(); var contactSource = new BindingSource(contactList, null); dataGridView1.AllowUserToAddRows = false; dataGridView1.DataSource = contactSource; // Logging BasicConfigurator.Configure(); // Events Load += MainForm_Load; FormClosing += MainForm_FormClosing; dataGridView1.RowsAdded += DataGridView1_RowsAdded; Icon = Icons.Logo.ToIcon(); // Extensions handlers = AddinExtensions.GetFiltered <CustomExtensionAttribute, IResponseHandler>().Select(v => v.Value).ToArray(); }
static Log4NetTracer() { PatternLayout layout = new PatternLayout(); layout.ConversionPattern = "%date [%thread] %-5level %logger [%ndc] - %message%newline"; layout.ActivateOptions(); FileAppender appender = new FileAppender(); appender.File = "Application.txt"; //ConsoleAppender appender = new ConsoleAppender(); appender.Layout = layout; appender.ActivateOptions(); Hierarchy hierarchy = (Hierarchy)LogManager.GetRepository(); Logger root = hierarchy.Root; root.Level = log4net.Core.Level.All; BasicConfigurator.Configure(appender); log4net.Config.BasicConfigurator.Configure(); }
public static void ConfigureLogging(Level threshold) { PatternLayout layout = new PatternLayout { ConversionPattern = "%d %-5p %c - %m%n" }; layout.ActivateOptions(); ConsoleAppender appender = new ConsoleAppender { Layout = layout, Threshold = threshold }; appender.ActivateOptions(); BasicConfigurator.Configure(appender); LogManager.Use <Log4NetFactory>(); }
public ReplicationBase() { for (int i = 0; i < 15; i++) { database::Raven.Database.Extensions.IOExtensions.DeleteDirectory("Data #" + i); } var outputDebugStringAppender = new OutputDebugStringAppender { Layout = new SimpleLayout(), }; outputDebugStringAppender.AddFilter(new LoggerMatchFilter { AcceptOnMatch = true, LoggerToMatch = "Raven.Bundles" }); outputDebugStringAppender.AddFilter(new DenyAllFilter()); BasicConfigurator.Configure(outputDebugStringAppender); }
public void should_completely_drop_log_event_when_log_event_pool_is_exhausted() { LogManager.Shutdown(); BasicConfigurator.Configure(new[] { _testAppender }, 10, 128, Level.Finest, LogEventPoolExhaustionStrategy.DropLogMessage); var log = LogManager.GetLogger(typeof(LogManagerTests)); var actualLogEvents = new List <ILogEvent>(); for (var i = 0; i < 10; i++) { actualLogEvents.Add(log.Debug()); } var signal = _testAppender.SetMessageCountTarget(1); log.Debug().Append("this is not going to happen").Log(); Check.That(signal.Wait(TimeSpan.FromMilliseconds(100))).IsFalse(); }
public int Divide(int i, int j) { int c = 0; BasicConfigurator.Configure(); try { if (j == 0) { throw new DivideByZeroException("Value should be grater than zero"); } c = i / j; return(c); } catch (DivideByZeroException ex) { log.Error(ex.Message); return(c); } }
public EndpointConfig() { var layout = new PatternLayout { ConversionPattern = "%d %-5p %c - %m%n" }; layout.ActivateOptions(); var appender = new ConsoleAppender { Layout = layout, Threshold = Level.Info }; appender.ActivateOptions(); BasicConfigurator.Configure(appender); LogManager.Use <Log4NetFactory>(); }
void IWantCustomLogging.Init() { PatternLayout layout = new PatternLayout { ConversionPattern = "%d %-5p %c - %m%n" }; layout.ActivateOptions(); ConsoleAppender appender = new ConsoleAppender { Layout = layout, Threshold = Level.Info }; appender.ActivateOptions(); BasicConfigurator.Configure(appender); SetLoggingLibrary.Log4Net(); }
public void TestStackTracePattern() { StringAppender stringAppender = new StringAppender(); stringAppender.Layout = NewPatternLayout("%stacktrace{2}"); ILoggerRepository rep = LogManager.CreateRepository(Guid.NewGuid().ToString()); BasicConfigurator.Configure(rep, stringAppender); ILog log1 = LogManager.GetLogger(rep.Name, "TestStackTracePattern"); log1.Info("TestMessage"); #if !MONO Assert.AreEqual("RuntimeMethodHandle._InvokeMethodFast > PatternLayoutTest.TestStackTracePattern", stringAppender.GetString(), "stack trace value set"); #else Assert.AreEqual("MonoMethod.InternalInvoke > PatternLayoutTest.TestStackTracePattern", stringAppender.GetString(), "stack trace value set"); #endif stringAppender.Reset(); }
static void BootstrapLogger() { string configurationFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "log4net.config"); var configurationFile = new FileInfo(configurationFilePath); // if we can't find the log4net configuration file, perform a basic configuration which at // least logs to trace/debug, which means we can attach a debugger // to the process! if (configurationFile.Exists) { XmlConfigurator.ConfigureAndWatch(configurationFile); } else { BasicConfigurator.Configure(); } _log.DebugFormat("Logging configuration loaded: {0}", configurationFilePath); }
static void Main(string[] args) { BasicConfigurator.Configure(); // commands // verify v // execute e // trace t (default) // args // environment /e:local - used to work with config files // part /p:all|web - a bastardized capistrano roles // deployment // /d:FHLBank.Flames.Deployment.dll (an assembly) // /d:FHLBank.Flames.Deployment.StandardDepoy (a class, lack of .dll) // (null) - if omitted search for a dll ending with 'Deployment' then pass that name in //goal Runner.Deploy(args.Aggregate((a, b) => a + " " + b).Trim()); }
/// <summary> /// Utility function to initialize logging. This will check for a log configuration file /// and use that to configure the logging. If the log configuration file is not available, /// this method will check the default log configuration file. If that file is not /// available either, this method will create a primitive configuration that writes logs to /// the filename specified as the defaultLogfileName /// </summary> /// <param name="configFilename">the path (can be relative) to the log config file</param> /// <param name="defaultConfigFilename">the path (can be relative) to the default log config file</param> /// <param name="defaultLogfileName">the filename to use for logging if the config files are not found</param> public static void InitializeLogging(string configFilename, string defaultConfigFilename, string defaultLogfileName, bool interactive) { if (File.Exists(configFilename)) { XmlConfigurator.ConfigureAndWatch(new FileInfo(configFilename)); } else if (File.Exists(defaultConfigFilename)) { XmlConfigurator.ConfigureAndWatch(new FileInfo(defaultConfigFilename)); } else { // should only get here if someone has a messed up install if (interactive) { RollingFileAppender rfa = new RollingFileAppender(); rfa.Layout = new PatternLayout("%-5p [%d{ISO8601}] %-20.20c{1} %m%n"); rfa.File = defaultLogfileName; rfa.AppendToFile = false; rfa.MaximumFileSize = "5MB"; rfa.MaxSizeRollBackups = 2; rfa.RollingStyle = RollingFileAppender.RollingMode.Once; rfa.ActivateOptions(); BasicConfigurator.Configure(rfa); SetLogLevel(log4net.Core.Level.Info, true); } else { // use the trace appender if we are not running interactive TraceAppender ta = new TraceAppender(); ta.Layout = new PatternLayout("%-5p [%d{ISO8601}] %-20.20c{1} %m%n"); ta.ActivateOptions(); BasicConfigurator.Configure(ta); SetLogLevel(log4net.Core.Level.Info, true); } logUtilLog.Info("Unable to find logging config files. Using fallback simple logging configuration."); logUtilLog.InfoFormat("Logging config file: {0}", configFilename); } }
private static void Main() { BasicConfigurator.Configure(); // Remove limits from Service Point Manager ServicePointManager.MaxServicePoints = 999999; ServicePointManager.DefaultConnectionLimit = 999999; ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls; ServicePointManager.CheckCertificateRevocationList = true; ServicePointManager.EnableDnsRoundRobin = true; // Run demo 1 //SimpleCrawlDemo.Run(); // Run demo 2 //CrawlUsingIsolatedStorage.Run(); // Run demo 3 //CrawlUsingEsentStorage.Run(); // Run demo 4 //CrawlUsingEfStorage.Run(); #if DOTNET4 // Run demo 5 //CrawlUsingSQLiteDbStorage.Run(); #endif // Run demo 6 //IndexerDemo.Run(); // Run demo 7 //FindBrokenLinksDemo.Run(); // Run demo 8 //AdvancedCrawlDemo.Run(); CrawlUsingFundServices.Run(); Console.Out.WriteLine("\nDone!"); }
static void Main() { Console.Title = "Samples.Logging.Log4NetCustom"; #region ConfigureLog4Net var layout = new PatternLayout { ConversionPattern = "%d [%t] %-5p %c [%x] - %m%n" }; layout.ActivateOptions(); var consoleAppender = new ConsoleAppender { Threshold = Level.Info, Layout = layout }; // Note that ActivateOptions is required in NSB 5 and above consoleAppender.ActivateOptions(); BasicConfigurator.Configure(consoleAppender); #endregion #region UseConfig LogManager.Use <Log4NetFactory>(); // Then continue with the bus configuration var busConfiguration = new BusConfiguration(); busConfiguration.EndpointName("Samples.Logging.Log4NetCustom"); #endregion busConfiguration.UseSerialization <JsonSerializer>(); busConfiguration.EnableInstallers(); busConfiguration.UsePersistence <InMemoryPersistence>(); using (var bus = Bus.Create(busConfiguration).Start()) { var myMessage = new MyMessage(); bus.SendLocal(myMessage); Console.WriteLine("Press any key to exit"); Console.ReadKey(); } }
public ILog GetLog() { if (this.configurationRoot == null) { this.configurationRoot = this.GetConfigurationRoot(this.fileFolderPath, this.fileName); } IConfigurationSection log4netSection = this.GetLog4NetConfigurationSection(this.configurationRoot); IEnumerable <AppenderSkeleton> appenders = this.GetAppenders(this.configurationRoot, log4netSection); IConfigurationSection loggerSection = this.GetLoggerSection(log4netSection); IConfigurationSection name = loggerSection.GetSection("name"); string repositoryName = String.Format("{0} Repository", name.Value); ILoggerRepository repository = LoggerManager.CreateRepository(repositoryName); string loggerName = String.Format("{0} Logger", name.Value); IConfigurationSection level = loggerSection.GetSection("level"); string levelName = "All"; if (level != null && !String.IsNullOrEmpty(level.Value)) { levelName = level.Value; } ILoggerRepository loggerRepository = LoggerManager.GetAllRepositories().FirstOrDefault(); LevelMatchFilter filter = new LevelMatchFilter(); filter.LevelToMatch = loggerRepository.LevelMap[levelName]; filter.ActivateOptions(); foreach (var appender in appenders) { appender.AddFilter(filter); appender.ActivateOptions(); BasicConfigurator.Configure(repository, appender); } ILog logger = LogManager.GetLogger(repositoryName, loggerName); return(logger); }
public void CreateLogger(string loggerName) { //It will create a repository for each different arg it will receive var repositoryName = "Netfox"; ILoggerRepository repository = null; var repositories = LogManager.GetAllRepositories(); foreach (var loggerRepository in repositories) { if (loggerRepository.Name.Equals(repositoryName)) { repository = loggerRepository; break; } } if (repository == null) { //Create a new repository repository = LogManager.CreateRepository(repositoryName); var hierarchy = (Hierarchy)repository; hierarchy.Root.Additivity = false; //Add appenders you need: here I need a rolling file and a memoryappender hierarchy.Root.AddAppender(this.NetfoxOutputAppender); hierarchy.Root.AddAppender(this.NetfoxFileAppender); BasicConfigurator.Configure(repository); } //Returns a logger from a particular repository; //Logger with same name but different repository will log using different appenders var logger = LogManager.GetLogger(repositoryName, loggerName); var logg = new ExtendedLog4netFactory(); this.Logger = new ExtendedLog4netLogger(logger, logg); }
public static ILog GetLogger(Type type) { if (_consoleAppender == null) { _consoleAppender = GetConsoleAppender(); } if (_rollingFileAppender == null) { _rollingFileAppender = GetRollingFileAppender(); } if (_logger != null) { return(_logger); } BasicConfigurator.Configure(_consoleAppender, _rollingFileAppender); _logger = LogManager.GetLogger(type); return(_logger); }
public void SetUp() { _fileFolderPath = TestHelper.MapPathForTest("~/LogTesting/"); _fileGuid = Guid.NewGuid(); if (File.Exists(GetFilePath())) { File.Delete(GetFilePath()); } _appender = new AsynchronousRollingFileAppender(); _appender.Threshold = _errorLevel; _appender.File = GetFilePath(); _appender.Layout = new PatternLayout("%d|%-5level|%logger| %message %exception%n"); _appender.StaticLogFileName = true; _appender.AppendToFile = true; _appender.ActivateOptions(); _rep = LogManager.CreateRepository(Guid.NewGuid().ToString()); BasicConfigurator.Configure(_rep, _appender); }
public void NoBufferingTest() { ILoggerRepository rep = LogManager.CreateRepository(Guid.NewGuid().ToString()); AdoNetAppender adoNetAppender = new AdoNetAppender(); adoNetAppender.BufferSize = -1; #if NETSTANDARD1_3 adoNetAppender.ConnectionType = typeof(Log4NetConnection).AssemblyQualifiedName; #else adoNetAppender.ConnectionType = "log4net.Tests.Appender.AdoNet.Log4NetConnection"; #endif adoNetAppender.ActivateOptions(); BasicConfigurator.Configure(rep, adoNetAppender); ILog log = LogManager.GetLogger(rep.Name, "NoBufferingTest"); log.Debug("Message"); Assert.NotNull(Log4NetCommand.MostRecentInstance); Assert.AreEqual(1, Log4NetCommand.MostRecentInstance.ExecuteNonQueryCount); }
public void Initialize() { List <IAppender> appenders = new List <IAppender>(); appenders.Add(CreateFileAppender()); var smtpAppender = CreateSmtpAppender(); if (smtpAppender != null) { appenders.Add(smtpAppender); } if (IsConsoleApplication) { appenders.Add(CreateConsoleAppender()); } BasicConfigurator.Configure(appenders.ToArray()); }
private ILoggerRepository CreateRepository(Log4NetSettings settings) { ILoggerRepository CreateAndInitializeRepo(string repoName) { var repo = LogManager.CreateRepository(repoName); var configFile = GetConfigFileFullPath(settings.ConfigFile); if (File.Exists(configFile)) { ConfigureRepositoryFromXml(repo, configFile, settings.Watch); } else { BasicConfigurator.Configure(repo); } return(repo); } return(_repositoryCache.GetOrAdd(settings.RootRepository, CreateAndInitializeRepo)); }
public void TestAddingCustomPattern() { StringAppender stringAppender = new StringAppender(); PatternLayout layout = new PatternLayout(); layout.AddConverter("TestAddingCustomPattern", typeof(TestMessagePatternConverter)); layout.ConversionPattern = "%TestAddingCustomPattern"; layout.ActivateOptions(); stringAppender.Layout = layout; ILoggerRepository rep = LogManager.CreateRepository(Guid.NewGuid().ToString()); BasicConfigurator.Configure(rep, stringAppender); ILog log1 = LogManager.GetLogger(rep.Name, "TestAddingCustomPattern"); log1.Info("TestMessage"); Assert.AreEqual("TestMessage", stringAppender.GetString(), "%TestAddingCustomPattern not registered"); stringAppender.Reset(); }
private void Initialize(Log4netConfiguration myLog4NetConfig, IHealthReporter myHealthReporter) { this.healthReporter = myHealthReporter; this._log4NetInputConfiguration = myLog4NetConfig; this.subject = new EventFlowSubject <EventData>(); //Can we determine if the repo exists without try/catch try { eventFlowRepo = (Hierarchy)LogManager.CreateRepository("EventFlowRepo"); _log4NetInputConfiguration.Log4netLevel = eventFlowRepo.LevelMap[_log4NetInputConfiguration.LogLevel]; eventFlowRepo.Root.AddAppender(this); eventFlowRepo.Configured = true; BasicConfigurator.Configure(eventFlowRepo); } catch (LogException) { eventFlowRepo = (Hierarchy)LogManager.GetRepository("EventFlowRepo"); } }
private static void AddCommandLineLogger() { //remove application logger... var root = ((log4net.Repository.Hierarchy.Hierarchy)LogManager.GetRepository()).Root; var attachable = (IAppenderAttachable)root; attachable.RemoveAllAppenders(); //add console logger... var layout = new PatternLayout("%message%newline"); layout.ActivateOptions(); var appender = new ConsoleAppender { Layout = layout, Threshold = Level.Debug }; BasicConfigurator.Configure(appender); // set level to Debug ((log4net.Repository.Hierarchy.Hierarchy)LogManager.GetRepository()).Root.Level = Level.Debug; ((log4net.Repository.Hierarchy.Hierarchy)LogManager.GetRepository()).RaiseConfigurationChanged(EventArgs.Empty); }
public void TestExceptionPattern() { StringAppender stringAppender = new StringAppender(); PatternLayout layout = new PatternLayout("%exception{stacktrace}"); stringAppender.Layout = layout; ILoggerRepository rep = LogManager.CreateRepository(Guid.NewGuid().ToString()); BasicConfigurator.Configure(rep, stringAppender); ILog log1 = LogManager.GetLogger(rep.Name, "TestExceptionPattern"); Exception exception = new Exception("Oh no!"); log1.Info("TestMessage", exception); Assert.AreEqual(SystemInfo.NullText, stringAppender.GetString()); stringAppender.Reset(); }
/// <summary>Ctor /// </summary> public Log4NetProvider(Log4NetProviderOptions options) { _options = options; _loggerRepository = LogManager.CreateRepository(options.LoggerRepositoryName); var file = new FileInfo(options.Log4NetConfigFile); if (!file.Exists) { file = new FileInfo(Path.Combine(AppContext.BaseDirectory, options.Log4NetConfigFile)); } if (file.Exists) { XmlConfigurator.ConfigureAndWatch(_loggerRepository, file); } else { BasicConfigurator.Configure(_loggerRepository, new ConsoleAppender { Layout = new PatternLayout() }); } }
public Log4NetFiltering() { #region Log4NetFilterUsage var appender = new ConsoleAppender { Threshold = Level.Debug, Layout = new SimpleLayout(), }; appender.AddFilter(new NServiceBusLogFilter()); appender.ActivateOptions(); var executingAssembly = Assembly.GetExecutingAssembly(); var repository = log4net.LogManager.GetRepository(executingAssembly); BasicConfigurator.Configure(repository, appender); NServiceBus.Logging.LogManager.Use <Log4NetFactory>(); #endregion }
public static void Main() { BasicConfigurator.Configure(); // int n = 5; Console.WriteLine("Enter a positive number "); string input = Console.ReadLine(); int n = 0; while (!int.TryParse(input, out n) || n < 0 || n > 100) { log.Error("User error attempt to generate a matrix of rang: " + input); Console.WriteLine("You haven't entered a correct positive number"); input = Console.ReadLine(); } DirectionSet2D directionSet = new DirectionSet2D(DIRECTIONS_COUNT, DIRECTION_X, DIRECTION_Y); Matrix matrix = new Matrix(n, directionSet); WalkEntireMatrix(matrix); matrix.PrintMatrix(); }