private void StartScriptCs() { var name = "WPFScript.csx"; var console = new WPFConsoleRelay(); var configurator = new LoggerConfigurator(LogLevel.Info); configurator.Configure(console); var logger = configurator.GetLogger(); var init = new InitializationServices(logger); init.GetAppDomainAssemblyResolver().Initialize(); var builder = new ScriptServicesBuilder(console, logger, null, null, init) .Cache() .Debug(false) .LogLevel(LogLevel.Info) .ScriptName(name) .Repl(); var modules = new string[0]; var extension = Path.GetExtension(name); //OVERRIDES builder.ScriptHostFactory <WPFScriptHostFactory>(); builder.ScriptEngine <RoslynScriptEngine>(); builder.LoadModules(extension, modules); //BUILD SERVICE _service = builder.Build(); _service.Executor.Initialize(Enumerable.Empty <string>(), _service.ScriptPackResolver.GetPacks(), new string[0]); var types = new Type[] { typeof(IConsole), typeof(ScriptContext), typeof(Newtonsoft.Json.Converters.BinaryConverter) }; _service.Executor.AddReferenceAndImportNamespaces(types); EventAggr.Instance.GetEvent <WriteLineEvent>().Subscribe((text) => { string[] lines = text.Split(new string[] { Environment.NewLine }, StringSplitOptions.None); foreach (var line in lines.Where(l => !string.IsNullOrEmpty(l))) { _area.Document.Text += line; NewLine(); _area.Document.Text += ">"; } }); EventAggr.Instance.GetEvent <WriteEvent>().Subscribe((text) => { _area.Document.Text += text; } ); }
private IScriptExecutor GetExecutor(List <string> references, string rootPath) { var console = new ScriptConsole(); var loggerConfig = new LoggerConfigurator(ScriptCs.Contracts.LogLevel.Error); loggerConfig.Configure(console); var logger = loggerConfig.GetLogger(); var builder = new ScriptServicesBuilder(console, logger). InMemory(true). ScriptName(""); var services = builder.Build(); var executor = services.Executor; var paths = services.AssemblyResolver.GetAssemblyPaths(rootPath, null).Where(p => !p.Contains("Contracts")); var packs = services.ScriptPackResolver.GetPacks(); executor.Initialize(paths, packs); executor.AddReferences(references.ToArray()); var reference = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + @"\ScriptCs.Contracts.dll"; executor.AddReferences(reference); executor.ImportNamespaces("ScriptCs.Contracts"); return(executor); }
public static void Register() { var server = HttpContext.Current.Server; var config = server.MapPath(ConfigurationManager.AppSettings["log4net.config"]); LoggerConfigurator.Configure(config); }
public Startup(IHostingEnvironment env) { SetDefaultApplicationConfiguration(); Configuration = new ConfigurationBuilder() .SetBasePath(env.ContentRootPath) .AddJsonFile("appsettings.json", true, true) .AddJsonFile($"appsettings.{env.EnvironmentName}.json", true) .AddEnvironmentVariables().Build(); Log.Logger = LoggerConfigurator.Configure(Configuration); }
public static IScriptServicesBuilder Create(ScriptCsArgs commandArgs, string[] scriptArgs) { Guard.AgainstNullArgument("commandArgs", commandArgs); Guard.AgainstNullArgument("scriptArgs", scriptArgs); IConsole console = new ScriptConsole(); if (!string.IsNullOrWhiteSpace(commandArgs.Output)) { console = new FileConsole(commandArgs.Output, console); } var configurator = new LoggerConfigurator(commandArgs.LogLevel); configurator.Configure(console); var logger = configurator.GetLogger(); var initializationServices = new InitializationServices(logger); initializationServices.GetAppDomainAssemblyResolver().Initialize(); var scriptServicesBuilder = new ScriptServicesBuilder(console, logger, null, null, initializationServices) .Cache(commandArgs.Cache) .Debug(commandArgs.Debug) .LogLevel(commandArgs.LogLevel) .ScriptName(commandArgs.ScriptName) .Repl(commandArgs.Repl); var modules = commandArgs.Modules == null ? new string[0] : commandArgs.Modules.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries); var extension = Path.GetExtension(commandArgs.ScriptName); if (string.IsNullOrWhiteSpace(extension) && !commandArgs.Repl) { // No extension was given, i.e we might have something like // "scriptcs foo" to deal with. We activate the default extension, // to make sure it's given to the LoadModules below. extension = ".csx"; if (!string.IsNullOrWhiteSpace(commandArgs.ScriptName)) { // If the was in fact a script specified, we'll extend it // with the default extension, assuming the user giving // "scriptcs foo" actually meant "scriptcs foo.csx". We // perform no validation here thought; let it be done by // the activated command. If the file don't exist, it's // up to the command to detect and report. commandArgs.ScriptName += extension; } } return scriptServicesBuilder.LoadModules(extension, modules); }
private ScriptServices CreateScriptServices(bool useLogging) { var console = new ScriptConsole(); var configurator = new LoggerConfigurator(useLogging ? LogLevel.Debug : LogLevel.Info); configurator.Configure(console); var logger = configurator.GetLogger(); var builder = new ScriptServicesBuilder(console, logger); builder.ScriptEngine<RoslynScriptEngine>(); return builder.Build(); }
public void TestLogger() { LoggerConfigurator.Configure(); var logger = LoggerManager.GetLogger(this.GetType()); logger.Info("logger info"); logger.Warn("logger warn"); logger.Debug("logger debug"); logger.Error("logger error"); logger.Fatal("logger fatal"); try { var i = 0; var j = 2 / i; } catch (Exception ex) { logger.Error(ex.Message, ex); } }
private static ScriptServices BuildScriptServices(InOutConsole console) { var logConfiguration = new LoggerConfigurator(LogLevel.Info); logConfiguration.Configure(console); var logger = logConfiguration.GetLogger(); var initializationServices = new InitializationServices(logger); initializationServices.GetAppDomainAssemblyResolver().Initialize(); var scriptServicesBuilder = new ScriptServicesBuilder(console, logger, null, null, initializationServices) .Repl(true); scriptServicesBuilder.LoadModules(""); var scriptServices = scriptServicesBuilder.Build(); initializationServices.GetInstallationProvider().Initialize(); scriptServices.Repl.Initialize(Enumerable.Empty<string>(), Enumerable.Empty<IScriptPack>()); return scriptServices; }