protected virtual void InitializeComponents() { if (Logger == null) { Logger = new StandardLogger(Console.Out, false); } if (ServiceProvider == null) { //if we have a kernel, then let's create a "depency-injection service provider". if (Kernel != null) { ServiceProvider = new DIServiceProvider(Kernel); } //otherwise, create a regular, plain service provider else { ServiceProvider = new ServiceProvider(); } } if (PresentationController == null) { PresentationController = new PresentationController(); } if (ApplicationModuleManager == null) { ApplicationModuleManager = new ApplicationModuleManager(); } ApplicationModuleManager.PresentationController = PresentationController; //if the Kernel is present, then link both module managers (from Foundation and from Ninject). if (Kernel != null) { ApplicationModuleManager.ModuleManager = Kernel.Components.ModuleManager; } }
public void AddLog_WithValidPoint_AddPointToVisitedPlace() { var sut = new StandardLogger(); sut.AddLog(new Point(1, 1)); Assert.AreEqual(1, sut.VisitedPoint.Count); }
protected internal ApplicationManager() { TextLogWriter writer = new TextLogWriter(new System.IO.MemoryStream()); writer.Level = LogLevel.Fatal; writer.AutoflushLevel = LogLevel.Fatal; writer.IsEnabled = false; Logger = new StandardLogger(writer); }
public void ReadLog_WhenNoVisitedPointsAreEqual_ReturnCountsOfVisitedPoints() { var sut = new StandardLogger(); sut.AddLog(new Point(1, 1)); sut.AddLog(new Point(2, 2)); Assert.IsTrue(sut.ReadLog().EndsWith("2")); }
public void AddLog_WithPointWhichAlreadyExsits_AddPointToVisitedPlace() { var sut = new StandardLogger(); sut.AddLog(new Point(1, 1)); sut.AddLog(new Point(1, 1)); Assert.AreEqual(2, sut.VisitedPoint.Count); }
protected internal virtual void OnReload() { if (Regenerate) { CopyFrom(new SelfConfig { Regenerate = false }); } StandardLogger.Configure(); }
public void ReadLog_WillReturnTheNumberOfEuniqueVisitedPoints() { var sut = new StandardLogger(); sut.AddLog(new Point(1, 1)); sut.AddLog(new Point(2, 2)); sut.AddLog(new Point(2, 2)); Assert.IsTrue(sut.ReadLog().EndsWith("2")); }
static void Main(string[] args) { Shell shell = new Shell(PeerGroupFactory.NewNetPeerGroup()); LogSelector logSelector = new LogSelector(); logSelector.InvertCategories = true; StandardLogger logger = new StandardLogger(); logger.LogSelector = logSelector; int logDepth = 2; for (int i = 0; i < args.Length; i++) { switch (args[i]) { case "-v": logDepth++; break; case "-f": if (args.Length > i) { logger.LogWriter = new StreamWriter(args[++i]); } break; default: Console.WriteLine("# Error - Bad option"); shell.PrintHelp(); return; } } if (logDepth > 0) { logSelector.AddLogLevel((LogLevels)((int)(Math.Pow(2, logDepth) - 1))); } GlobalLogger.AppendLogEvent += logger.AppendLogMessage; GlobalLogger.StartLogging(); shell.PrintWelcome(); shell.ControlLoop(); Console.WriteLine("Exiting Jxta.NET Shell"); GlobalLogger.StopLogging(); GlobalLogger.AppendLogEvent -= logger.AppendLogMessage; }
public DialogResult ShowDialog(IWin32Window owner, string deviceName, string parameterName, DriverSettingAttribute attribute, string initialValue) { ILogger logger = new StandardLogger(SharedLibrary.LoggerContextType.Driver, "Venstar", SharedLibrary.LoggerVerbosity.Detailed); logger.Info(deviceName); logger.Info(parameterName); logger.Info(initialValue); using (ThermostatIdentifiersDriverSettingEditorForm settingEditorForm = new ThermostatIdentifiersDriverSettingEditorForm(parameterName, attribute, initialValue, logger)) { DialogResult dialogResult = settingEditorForm.ShowDialog(owner); this.value = dialogResult != DialogResult.OK ? (string)null : settingEditorForm.Value; return dialogResult; } }
protected virtual void InitializeComponents() { if (Logger == null) { TextLogWriter writer = new TextLogWriter(new System.IO.MemoryStream()); writer.AutoflushLevel = LogLevel.Fatal; writer.IsEnabled = false; Logger = new StandardLogger(writer); } if (ServiceProvider == null) { //if we have a kernel, then let's create a "depency-injection service provider". if (Kernel != null) { ServiceProvider = new DIServiceProvider(Kernel); } //otherwise, create a regular, plain service provider else { ServiceProvider = new ServiceProvider(); } } if (PresentationController == null) { PresentationController = new PresentationController(); } if (ApplicationModuleManager == null) { ApplicationModuleManager = new ApplicationModuleManager(); } ApplicationModuleManager.PresentationController = PresentationController; //if the Kernel is present, then link both module managers (from Foundation and from Ninject). if (Kernel != null) { ApplicationModuleManager.ModuleManager = Kernel.Components.ModuleManager; } }
public static Task Main(string[] args) { IConfiguration configuration = new ConfigurationBuilder() .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true) .AddCommandLine(args) .Build(); var serviceCollection = new ServiceCollection(); ConfigureServices(serviceCollection, configuration); var serviceProvider = serviceCollection.BuildServiceProvider(); var logger = new StandardLogger(serviceProvider.GetRequiredService <ILogger <Program> >()); Parser.Default.ParseArguments <Options.InitializeOptions, Options.ListenOptions, Options.ClearStatefulSubscriberErrorsOptions, Options.ResetStatefulSubscribersOptions>(args) .WithParsed <Options.InitializeOptions>(options => new Actions.InitializeAction(options, logger, configuration).RunAsync().Wait()) .WithParsed <Options.ListenOptions>(options => new Actions.ListenAction(options, logger, configuration).RunAsync().Wait()) .WithParsed <Options.ClearStatefulSubscriberErrorsOptions>(options => new Actions.ClearStatefulSubscriberErrorsAction(options, logger, configuration).RunAsync().Wait()) .WithParsed <Options.ResetStatefulSubscribersOptions>(options => new Actions.ResetStatefulSubscribersAction(options, logger, configuration).RunAsync().Wait()); ((IDisposable)serviceProvider)?.Dispose(); // Force flush log messages to output. return(Task.CompletedTask); }
private static Tuple <IEnumerable <BSPluginMeta>, IEnumerable <IPlugin> > LoadPluginsFromFile(string file, string exeName) { List <BSPluginMeta> bsPlugins = new List <BSPluginMeta>(); List <IPlugin> ipaPlugins = new List <IPlugin>(); if (!File.Exists(file) || !file.EndsWith(".dll", true, null)) { return(new Tuple <IEnumerable <BSPluginMeta>, IEnumerable <IPlugin> >(bsPlugins, ipaPlugins)); } T OptionalGetPlugin <T>(Type t) where T : class { // use typeof() to allow for easier renaming (in an ideal world this compiles to a string, but ¯\_(ツ)_/¯) if (t.GetInterface(typeof(T).Name) != null) { try { T pluginInstance = Activator.CreateInstance(t) as T; string[] filter = null; if (pluginInstance is IGenericEnhancedPlugin) { filter = ((IGenericEnhancedPlugin)pluginInstance).Filter; } if (filter == null || filter.Contains(exeName, StringComparer.OrdinalIgnoreCase)) { return(pluginInstance); } } catch (Exception e) { Logger.log.Error($"Could not load plugin {t.FullName} in {Path.GetFileName(file)}! {e}"); } } return(null); } try { Assembly assembly = Assembly.LoadFrom(file); foreach (Type t in assembly.GetTypes()) { IBeatSaberPlugin bsPlugin = OptionalGetPlugin <IBeatSaberPlugin>(t); if (bsPlugin != null) { try { var init = t.GetMethod("Init", BindingFlags.Instance | BindingFlags.Public); if (init != null) { var initArgs = new List <object>(); var initParams = init.GetParameters(); LoggerBase modLogger = null; IModPrefs modPrefs = null; foreach (var param in initParams) { var ptype = param.ParameterType; if (ptype.IsAssignableFrom(typeof(LoggerBase))) { if (modLogger == null) { modLogger = new StandardLogger(bsPlugin.Name); } initArgs.Add(modLogger); } else if (ptype.IsAssignableFrom(typeof(IModPrefs))) { if (modPrefs == null) { modPrefs = new ModPrefs(bsPlugin); } initArgs.Add(modPrefs); } else { initArgs.Add(ptype.GetDefault()); } } init.Invoke(bsPlugin, initArgs.ToArray()); } bsPlugins.Add(new BSPluginMeta { Plugin = bsPlugin, Filename = file.Replace("\\.cache", ""), // quick and dirty fix ModsaberInfo = bsPlugin.ModInfo }); } catch (AmbiguousMatchException) { Logger.log.Error($"Only one Init allowed per plugin"); } } else { IPlugin ipaPlugin = OptionalGetPlugin <IPlugin>(t); if (ipaPlugin != null) { ipaPlugins.Add(ipaPlugin); } } } } catch (Exception e) { Logger.log.Error($"Could not load {Path.GetFileName(file)}! {e}"); } return(new Tuple <IEnumerable <BSPluginMeta>, IEnumerable <IPlugin> >(bsPlugins, ipaPlugins)); }
/// <summary> /// Create request function that returns a new request. A StandardLogger implementations can be provided. If omitted, the Logger /// instance will be provided by the LoggerFactory. /// </summary> /// <param name="logger"></param> /// <returns></returns> public Request CreateRequest(StandardLogger logger) { return(new Request(logger)); }
public static Logger GetStandardLogger(StandardLogger standardLogger) { return(NLogManager.Instance.GetFileTargetLogger(standardLogger.ToString())); }