private static int Main(string[] args) { #if DEBUG LogManager.AddDebugListener(true); #endif var consoleLogListener = new ConsoleLogListener(); LogManager.AddListener(consoleLogListener); var exitCode = 0; try { Log.Info("Example console app"); } catch (Exception ex) { Log.Error(ex, "An unknown exception occurred"); exitCode = -1; } #if DEBUG if (Debugger.IsAttached) { WaitForKeyPress(); } #endif return(exitCode); }
private int Rewrite() { var exitCode = 0; try { var consoleLogListener = new ConsoleLogListener(); Logger.RegisterListener(consoleLogListener); var sourceDirInfo = new DirectoryInfo(_srcDirectory); var fileInfos = sourceDirInfo.GetFiles("*.md", SearchOption.AllDirectories); Console.WriteLine("Start transform dir '{0}' to dest dir '{1}' at {2}", _srcDirectory, _destDirectory, DateTime.UtcNow); Parallel.ForEach( fileInfos, new ParallelOptions() { MaxDegreeOfParallelism = 8 }, fileInfo => { var relativePathToSourceFolder = fileInfo.FullName.Substring(_srcDirectory.Length + 1); try { if (IsIgnoreFile(relativePathToSourceFolder)) { return; } var outputPath = Path.Combine(_destDirectory, relativePathToSourceFolder); Directory.CreateDirectory(Path.GetDirectoryName(outputPath)); if (string.Equals(fileInfo.Extension, MarkdownExtension, StringComparison.OrdinalIgnoreCase)) { Console.WriteLine("Convert article {0}", fileInfo.FullName); var source = File.ReadAllText(fileInfo.FullName); var result = AzureMarked.Markup(source, fileInfo.FullName, _azureMarkdownFileInfoMapping, _azureVideoInfoMapping, _azureResourceFileInfoMapping); File.WriteAllText(outputPath, result); } else { //Console.WriteLine("Copy file {0} to output path {1}", fileInfo.FullName, outputPath); //File.Copy(fileInfo.FullName, outputPath, true); } } catch (Exception e) { exitCode = 1; Console.WriteLine($"Transform article: {relativePathToSourceFolder} failed. Exception: {e}"); } }); Console.WriteLine("End transform dir '{0}' to dest dir '{1}' at {2}", _srcDirectory, _destDirectory, DateTime.UtcNow); } finally { Logger.Flush(); Logger.UnregisterAllListeners(); } return(exitCode); }
static int Main(string[] args) { try { var consoleLogListener = new ConsoleLogListener(); Logger.RegisterListener(consoleLogListener); Options options; var result = TryGetOptions(args, out options); if (!string.IsNullOrWhiteSpace(options.Log)) { Logger.RegisterListener(new ReportLogListener(options.Log)); } if (options.LogLevel.HasValue) { Logger.LogLevelThreshold = options.LogLevel.Value; } if (!string.IsNullOrEmpty(result.Message)) { Logger.Log(result); } if (result.ResultLevel == ResultLevel.Error) { return(1); } var replayListener = new ReplayLogListener(); replayListener.AddListener(consoleLogListener); Logger.RegisterListener(replayListener); Logger.UnregisterListener(consoleLogListener); var context = new RunningContext(); result = Exec(options, context); if (!string.IsNullOrEmpty(result.Message)) { Logger.Log(result); } if (result.ResultLevel == ResultLevel.Error) { return(1); } if (result.ResultLevel == ResultLevel.Warning) { return(2); } return(0); } finally { Logger.Flush(); Logger.UnregisterAllListeners(); } }
public CatelLoggerService(bool enableConsoleListener) { if (enableConsoleListener) { var logListener = new ConsoleLogListener { IgnoreCatelLogging = true }; LogManager.AddListener(logListener); } }
private static void Main(string[] args) { if (args.Length == 0) { Console.WriteLine("Missing directory path argument"); return; } var directoryPath = args[0]; // @"D:\Modding\Persona 5 EU\Main game\ExtractedClean" var logger = new Logger(nameof(AtlusFlowScriptExtractor)); var listener = new ConsoleLogListener(true, LogLevel.All); listener.Subscribe(logger); using (var streamWriter = FileUtils.CreateText("AtlusFlowScriptExtractorOutput.txt")) { foreach (var file in Directory.EnumerateFiles(directoryPath, "*", SearchOption.AllDirectories)) { foreach (var foundScript in FindFlowScripts(file)) { var decompiler = new FlowScriptDecompiler(); decompiler.AddListener(listener); decompiler.Library = LibraryLookup.GetLibrary("p5"); decompiler.DecompileMessageScript = false; if (!decompiler.TryDecompile(foundScript.Item1, out var compilationUnit)) { logger.Error($"Failed to decompile FlowScript in: {foundScript.Item2}"); continue; } var writer = new CompilationUnitWriter(); streamWriter.WriteLine(); streamWriter.WriteLine("//"); streamWriter.WriteLine($"// File: {foundScript.Item2}"); streamWriter.WriteLine("//"); streamWriter.WriteLine(); writer.Write(compilationUnit, streamWriter); } } } logger.Info("Done"); }
private static void OnOpenConsoleClick(System.Windows.Forms.MenuItem menuItem) { menuItem.Enabled = false; // Check if not already done if (ConsoleVisible) { return; } ConsoleVisible = true; // Show console ConsoleLogListener.ShowConsole(); // Enable console logging var consoleLogListener = new ConsoleLogListener { LogMode = ConsoleLogMode.Always }; GlobalLogger.GlobalMessageLogged += consoleLogListener; }
public void Log_logs_an_entry_to_console() { DateTime testTime = DateTime.Now; Logger logger = new Logger(LogLevel.Error); ConsoleLogListener listener = new ConsoleLogListener(); listener.TestTime = testTime; logger.Listeners.Add(listener); string message = Guid.NewGuid().ToString(); string expected = testTime.ToString("s") + " " + message; var actual = new StringWriter(); Console.SetOut(actual); logger.LogError(message); Assert.IsTrue(actual.ToString().Contains(expected)); }
internal static int ExecSubCommand(string[] args) { EnvironmentContext.SetVersion(typeof(Program).Assembly.GetName().Version.ToString()); var consoleLogListener = new ConsoleLogListener(); var aggregatedLogListener = new AggregatedLogListener(); Logger.RegisterListener(consoleLogListener); Logger.RegisterListener(aggregatedLogListener); CommandController controller = null; ISubCommand command; try { controller = ArgsParser.Instance.Parse(args); command = controller.Create(); } catch (Exception e) when(e is System.IO.FileNotFoundException fe || e is DocfxException || e is JsonSerializationException) { Logger.LogError(e.Message); return(1); } catch (Exception e) when(e is OptionParserException || e is InvalidOptionException) { Logger.LogError(e.Message); if (controller != null) { Console.WriteLine(controller.GetHelpText()); } return(1); } catch (Exception ex) { Logger.LogError(ex.ToString()); if (controller != null) { Console.WriteLine(controller.GetHelpText()); } return(1); } if (command.AllowReplay) { Logger.RegisterAsyncListener(new AggregatedLogListener(aggregatedLogListener)); } Logger.UnregisterListener(aggregatedLogListener); var context = new SubCommandRunningContext(); PerformanceScope scope = null; try { // TODO: For now reuse AllowReplay for overall elapsed time statistics if (command.AllowReplay) { scope = new PerformanceScope(string.Empty, LogLevel.Info); } command.Exec(context); return(0); } catch (Exception e) when(e is DocumentException || e is DocfxException) { Logger.LogError(e.Message); return(1); } catch (Exception e) { Logger.LogError(e.ToString()); return(1); } finally { scope?.Dispose(); } }
static int Main(string[] args) { var exeName = Path.GetFileName(Assembly.GetExecutingAssembly().Location); var showHelp = false; var isSavingMode = false; int exitCode = 0; var p = new OptionSet { "Copyright (C) 2011-2013 Silicon Studio Corporation. All Rights Reserved", "Xenko Fix Project References - Version: " + String.Format( "{0}.{1}.{2}", typeof(FixProjectReference).Assembly.GetName().Version.Major, typeof(FixProjectReference).Assembly.GetName().Version.Minor, typeof(FixProjectReference).Assembly.GetName().Version.Build) + string.Empty, string.Format("Usage: {0} [options]* inputSlnFile", exeName), string.Empty, "=== Options ===", string.Empty, { "h|help", "Show this message and exit", v => showHelp = v != null }, { "s|save", "Save mode. By default doesn't save projects", v => isSavingMode = v != null }, string.Empty, "Return codes: 0 (success), 1 (error), 2 (project needs to be updated)", }; try { var inputFiles = p.Parse(args); if (showHelp) { p.WriteOptionDescriptions(Console.Out); return(0); } if (inputFiles.Count != 1) { throw new OptionException("Expect only one input file", ""); } var inputFile = inputFiles[0]; var consoleLogListener = new ConsoleLogListener { LogMode = ConsoleLogMode.Always }; GlobalLogger.GlobalMessageLogged += consoleLogListener; var log = GlobalLogger.GetLogger("FixProjectReference"); if (!ProcessCopyLocals(log, inputFile, isSavingMode)) { exitCode = 2; // Project needs to be updated } } catch (Exception e) { Console.WriteLine("{0}: {1}", exeName, e); if (e is OptionException) { p.WriteOptionDescriptions(Console.Out); } exitCode = 1; } return(exitCode); }
private static int ExecSubCommand(string[] args) { var consoleLogListener = new ConsoleLogListener(); var replayListener = new ReplayLogListener(); replayListener.AddListener(consoleLogListener); Logger.RegisterListener(replayListener); CommandController controller = null; ISubCommand command; try { controller = ArgsParser.Instance.Parse(args); command = controller.Create(); } catch (System.IO.FileNotFoundException fe) { Logger.LogError(fe.Message); return(1); } catch (Exception e) when(e is OptionParserException || e is InvalidOptionException) { Logger.LogError(e.Message); if (controller != null) { Console.WriteLine(controller.GetHelpText()); } return(1); } catch (Exception ex) { Logger.LogError(ex.ToString()); if (controller != null) { Console.WriteLine(controller.GetHelpText()); } return(1); } replayListener.Replay = command.AllowReplay; var context = new SubCommandRunningContext(); try { ThreadPool.SetMinThreads(4, 4); using (new PerformanceScope("executing", LogLevel.Info)) { command.Exec(context); } return(0); } catch (DocumentException de) { Logger.LogError(de.Message); return(1); } catch (DocfxException de) { Logger.LogError(de.Message); return(1); } catch (Exception e) { Logger.LogError(e.ToString()); return(1); } }
private static int Main(string[] args) { try { var exitCode = 0; if (args.Length != 3 && args.Length != 4) { PrintUsage(); return(1); } // Parse the basic arguments var rewriterToolArguments = ParseRewriterToolArgumentsFile(args[0], args[1], args[2]); if (rewriterToolArguments == null) { return(1); } // Register logger var consoleLogListener = new ConsoleLogListener(); var htmlLogFile = Path.Combine(rewriterToolArguments.AzureTransformArgumentsList.First().SourceDir, "log", "log.html"); if (File.Exists(htmlLogFile)) { File.Delete(htmlLogFile); } var htmlLogListener = new HtmlLogListener(htmlLogFile); Logger.RegisterListener(consoleLogListener); Logger.RegisterListener(htmlLogListener); // Parse advanced migration parameters AzureFileInformationCollection azureFileInformationCollection = new AzureFileInformationCollection(); if (args.Length == 4) { azureFileInformationCollection.AzureVideoInfoMapping = AzureVideoHelper.ParseAzureVideoFile(args[3], rewriterToolArguments.IsMigration); } if (rewriterToolArguments.IsMigration) { GenerateAzureFileInfoForMigration(args[0], rewriterToolArguments, args[2], azureFileInformationCollection); } else { GenerateAzureFileInfo(args[0], rewriterToolArguments, args[2], azureFileInformationCollection); } foreach (var azureTransformArguments in rewriterToolArguments.AzureTransformArgumentsList) { var p = new Program(rewriterToolArguments.IsMigration, azureTransformArguments.SourceDir, azureTransformArguments.DestDir, azureFileInformationCollection); if (!p.CheckParameters()) { continue; } var result = p.Rewrite(); if (result != 0) { exitCode = result; } } return(exitCode); } catch (Exception ex) { Console.Error.WriteLine(ex); return(1); } finally { Logger.Flush(); Logger.UnregisterAllListeners(); } }
private static int Main(string[] args) { var exeName = Path.GetFileName(Assembly.GetExecutingAssembly().Location); var showHelp = false; var options = new BuilderOptions(Logger.GetLogger("BuildEngine")); var p = new OptionSet { "Copyright (c) Stride contributors (https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp) All Rights Reserved", "Stride Build Tool - Version: " + String.Format( "{0}.{1}.{2}", typeof(Program).Assembly.GetName().Version.Major, typeof(Program).Assembly.GetName().Version.Minor, typeof(Program).Assembly.GetName().Version.Build) + string.Empty, string.Format("Usage: {0} [options]* inputfile -o outputfile", exeName), string.Empty, "=== Options ===", string.Empty, { "h|help", "Show this message and exit", v => showHelp = v != null }, { "v|verbose", "Show more verbose progress logs", v => options.Verbose = v != null }, { "d|debug", "Show debug logs (imply verbose)", v => options.Debug = v != null }, { "c|clean", "Clean the command cache, forcing to rebuild everything at the next build.", v => options.BuilderMode = Builder.Mode.Clean }, { "cd|clean-delete", "Clean the command cache and delete output objects", v => options.BuilderMode = Builder.Mode.CleanAndDelete }, { "b|build-path=", "Build path", v => options.BuildDirectory = v }, { "mdb|metadata-database=", "Optional ; indicate the directory containing the Metadata database, if used.", v => { if (!string.IsNullOrEmpty(v)) { options.MetadataDatabaseDirectory = v; } } }, { "o|output-path=", "Optional ; indicate an output path to copy the built assets in.", v => options.OutputDirectory = v }, { "cfg|config=", "Configuration name", v => options.Configuration = v }, { "log", "Enable file logging", v => options.EnableFileLogging = v != null }, { "log-file=", "Log build in a custom file.", v => { options.EnableFileLogging = v != null; options.CustomLogFileName = v; } }, { "monitor-pipe=", "Monitor pipe.", v => { if (!string.IsNullOrEmpty(v)) { options.MonitorPipeNames.Add(v); } } }, { "slave=", "Slave pipe", v => options.SlavePipe = v }, // Benlitz: I don't think this should be documented { "s|sourcebase=", "Optional ; Set the base directory for the source files. Not required if all source paths are absolute", v => options.SourceBaseDirectory = v }, { "a|append", "If set, the existing asset mappings won't be deleted.", v => options.Append = v != null }, { "t|threads=", "Number of threads to create. Default value is the number of hardware threads available.", v => options.ThreadCount = int.Parse(v) }, { "p|plugin=", "Add plugin directory.", v => { if (!string.IsNullOrEmpty(v)) { options.Plugins.AddPluginFolder(v); } } }, { "test=", "Run a test session.", v => options.TestName = v } }; TextWriterLogListener fileLogListener = null; // Output logs to the console with colored messages if (options.SlavePipe == null) { var consoleLogListener = new ConsoleLogListener { TextFormatter = FormatLog }; GlobalLogger.MessageLogged += consoleLogListener; } // Setting up plugin manager options.Plugins.AddPluginFolder(Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) ?? "", "BuildPlugins")); options.Plugins.Register(); BuildResultCode exitCode; try { options.InputFiles = p.Parse(args); // Also write logs from master process into a file if (options.SlavePipe == null) { if (options.EnableFileLogging) { string logFileName = options.CustomLogFileName; if (string.IsNullOrEmpty(logFileName)) { string inputName = "NoInput"; if (options.InputFiles.Count > 0) { inputName = Path.GetFileNameWithoutExtension(options.InputFiles[0]); } logFileName = "Logs/Build-" + inputName + "-" + DateTime.Now.ToString("yy-MM-dd-HH-mm") + ".txt"; } string dirName = Path.GetDirectoryName(logFileName); if (dirName != null) { Directory.CreateDirectory(dirName); } fileLogListener = new TextWriterLogListener(new FileStream(logFileName, FileMode.Create)) { TextFormatter = FormatLog }; GlobalLogger.MessageLogged += fileLogListener; } options.Logger.Info("BuildEngine arguments: " + string.Join(" ", args)); options.Logger.Info("Starting builder."); } if (showHelp) { p.WriteOptionDescriptions(Console.Out); exitCode = BuildResultCode.Successful; } else if (!string.IsNullOrEmpty(options.TestName)) { var test = new TestSession(); test.RunTest(options.TestName, options.Logger); exitCode = BuildResultCode.Successful; } else { exitCode = BuildEngineCommands.Build(options); } } catch (OptionException e) { options.Logger.Error("{0}", e); exitCode = BuildResultCode.CommandLineError; } catch (Exception e) { options.Logger.Error("{0}", e); exitCode = BuildResultCode.BuildError; } finally { if (fileLogListener != null) { fileLogListener.LogWriter.Close(); } } return((int)exitCode); }
private static int Main(string[] args) { clock = Stopwatch.StartNew(); // TODO this is hardcoded. Check how to make this dynamic instead. RuntimeHelpers.RunModuleConstructor(typeof(IProceduralModel).Module.ModuleHandle); RuntimeHelpers.RunModuleConstructor(typeof(MaterialKeys).Module.ModuleHandle); RuntimeHelpers.RunModuleConstructor(typeof(SpriteFontAsset).Module.ModuleHandle); RuntimeHelpers.RunModuleConstructor(typeof(ModelAsset).Module.ModuleHandle); //var project = new Package(); //project.Save("test.pdxpkg"); //Thread.Sleep(10000); //var spriteFontAsset = StaticFontAsset.New(); //Asset.Save("test.pdxfnt", spriteFontAsset); //project.Refresh(); //args = new string[] { "test.pdxpkg", "-o:app_data", "-b:tmp", "-t:1" }; var exeName = Path.GetFileName(Assembly.GetExecutingAssembly().Location); var showHelp = false; var options = new PackageBuilderOptions(new ForwardingLoggerResult(GlobalLogger.GetLogger("BuildEngine"))); var p = new OptionSet { "Copyright (C) 2011-2014 Silicon Studio Corporation. All Rights Reserved", "Paradox Build Tool - Version: " + String.Format( "{0}.{1}.{2}", typeof(Program).Assembly.GetName().Version.Major, typeof(Program).Assembly.GetName().Version.Minor, typeof(Program).Assembly.GetName().Version.Build) + string.Empty, string.Format("Usage: {0} inputPackageFile [options]* -b buildPath", exeName), string.Empty, "=== Options ===", string.Empty, { "h|help", "Show this message and exit", v => showHelp = v != null }, { "v|verbose", "Show more verbose progress logs", v => options.Verbose = v != null }, { "d|debug", "Show debug logs (imply verbose)", v => options.Debug = v != null }, { "log", "Enable file logging", v => options.EnableFileLogging = v != null }, { "p|profile=", "Profile name", v => options.BuildProfile = v }, { "project-configuration=", "Project configuration", v => options.ProjectConfiguration = v }, { "platform=", "Platform name", v => options.Platform = (PlatformType)Enum.Parse(typeof(PlatformType), v) }, { "graphics-platform=", "Graphics Platform name", v => options.GraphicsPlatform = (GraphicsPlatform)Enum.Parse(typeof(GraphicsPlatform), v) }, { "solution-file=", "Solution File Name", v => options.SolutionFile = v }, { "package-id=", "Package Id from the solution file", v => options.PackageId = Guid.Parse(v) }, { "package-file=", "Input Package File Name", v => options.PackageFile = v }, { "o|output-path=", "Output path", v => options.OutputDirectory = v }, { "b|build-path=", "Build path", v => options.BuildDirectory = v }, { "log-file=", "Log build in a custom file.", v => { options.EnableFileLogging = v != null; options.CustomLogFileName = v; } }, { "log-pipe=", "Log pipe.", v => { if (!string.IsNullOrEmpty(v)) { options.LogPipeNames.Add(v); } } }, { "monitor-pipe=", "Monitor pipe.", v => { if (!string.IsNullOrEmpty(v)) { options.MonitorPipeNames.Add(v); } } }, { "slave=", "Slave pipe", v => options.SlavePipe = v }, // Benlitz: I don't think this should be documented { "t|threads=", "Number of threads to create. Default value is the number of hardware threads available.", v => options.ThreadCount = int.Parse(v) }, { "test=", "Run a test session.", v => options.TestName = v }, { "property:", "Properties. Format is name1=value1;name2=value2", v => { if (!string.IsNullOrEmpty(v)) { foreach (var nameValue in v.Split(new [] { ';' }, StringSplitOptions.RemoveEmptyEntries)) { var equalIndex = nameValue.IndexOf('='); if (equalIndex == -1) { throw new OptionException("Expect name1=value1;name2=value2 format.", "property"); } options.Properties.Add(nameValue.Substring(0, equalIndex), nameValue.Substring(equalIndex + 1)); } } } }, { "compile-property:", "Compile properties. Format is name1=value1;name2=value2", v => { if (!string.IsNullOrEmpty(v)) { if (options.ExtraCompileProperties == null) { options.ExtraCompileProperties = new Dictionary <string, string>(); } foreach (var nameValue in v.Split(new [] { ';' }, StringSplitOptions.RemoveEmptyEntries)) { var equalIndex = nameValue.IndexOf('='); if (equalIndex == -1) { throw new OptionException("Expect name1=value1;name2=value2 format.", "property"); } options.ExtraCompileProperties.Add(nameValue.Substring(0, equalIndex), nameValue.Substring(equalIndex + 1)); } } } }, }; TextWriterLogListener fileLogListener = null; // Output logs to the console with colored messages if (options.SlavePipe == null) { var consoleLogListener = new ConsoleLogListener { TextFormatter = FormatLog, LogMode = ConsoleLogMode.Always }; GlobalLogger.GlobalMessageLogged += consoleLogListener; } BuildResultCode exitCode; try { var unexpectedArgs = p.Parse(args); if (unexpectedArgs.Any()) { throw new OptionException("Unexpected arguments [{0}]".ToFormat(string.Join(", ", unexpectedArgs)), "args"); } try { options.ValidateOptions(); } catch (ArgumentException ex) { throw new OptionException(ex.Message, ex.ParamName); } // Also write logs from master process into a file if (options.SlavePipe == null) { if (options.EnableFileLogging) { string logFileName = options.CustomLogFileName; if (string.IsNullOrEmpty(logFileName)) { string inputName = Path.GetFileNameWithoutExtension(options.PackageFile); logFileName = "Logs/Build-" + inputName + "-" + DateTime.Now.ToString("yy-MM-dd-HH-mm") + ".txt"; } string dirName = Path.GetDirectoryName(logFileName); if (dirName != null) { Directory.CreateDirectory(dirName); } fileLogListener = new TextWriterLogListener(new FileStream(logFileName, FileMode.Create)) { TextFormatter = FormatLog }; GlobalLogger.GlobalMessageLogged += fileLogListener; } options.Logger.Info("BuildEngine arguments: " + string.Join(" ", args)); options.Logger.Info("Starting builder."); } if (showHelp) { p.WriteOptionDescriptions(Console.Out); exitCode = BuildResultCode.Successful; } else if (!string.IsNullOrEmpty(options.TestName)) { var test = new TestSession(); test.RunTest(options.TestName, options.Logger); exitCode = BuildResultCode.Successful; } else { var builder = new PackageBuilder(options); Console.CancelKeyPress += (_, e) => e.Cancel = builder.Cancel(); exitCode = builder.Build(); } } catch (OptionException e) { options.Logger.Error("Command option '{0}': {1}", e.OptionName, e.Message); exitCode = BuildResultCode.CommandLineError; } catch (Exception e) { options.Logger.Error("Unhandled exception: {0}", e, e.Message); exitCode = BuildResultCode.BuildError; } finally { if (fileLogListener != null) { fileLogListener.LogWriter.Close(); } } return((int)exitCode); }
public void TestGetConfigWithNoInputAndDocfxJsonExists() { // Create default template var defaultTemplate = @" {{{rawTitle}}}{{{conceptual}}} "; Directory.CreateDirectory(Path.Combine(_templateFolder, "default")); Directory.CreateDirectory(_inputFolder); Directory.CreateDirectory(_outputFolder); File.WriteAllText(Path.Combine(_templateFolder, "default", "Conceptual.html.tmpl"), defaultTemplate); // use `/` as it will be used in glob pattern // In glob pattern, `/` is considered as file separator while `\` is considered as escape character var conceptualFile1 = _inputFolder + "/test1.md"; File.WriteAllLines( conceptualFile1, new[] { "---", "uid: xref1", "a: b", "b:", " c: e", "---", "# Hello Test1", "Test XRef: @xref2", "Test XRef: @unknown_xref", "Test XRef: [<img src=\".\">](xref:xref2)", "Test link: [link text](test2.md)", "<p>", "test", }); var conceptualFile2 = _inputFolder + "/test2.md"; File.WriteAllLines( conceptualFile2, new[] { "---", "uid: xref2", "a: b", "b:", " c: e", "---", "# Hello World", "Test XRef: [](xref:xref1)", "Test XRef auto link: <xref:xref1>", "Test link: [link text](test1.md)", "<p>", "test", }); var console = new ConsoleLogListener(); Logger.RegisterListener(console); try { new BuildCommand(new BuildCommandOptions { Content = new List <string> { conceptualFile1, conceptualFile2 }, OutputFolder = Path.Combine(Directory.GetCurrentDirectory(), _outputFolder), Templates = new List <string> { Path.Combine(_templateFolder, "default") }, LruSize = 1, }).Exec(null); } finally { Logger.UnregisterListener(console); } var file = Path.Combine(_outputFolder, Path.ChangeExtension(conceptualFile1, ".html")); Assert.True(File.Exists(file)); Assert.Equal <string>( new string[] { "", "<h1 id=\"hello-test1\">Hello Test1</h1>", "<p>Test XRef: <a class=\"xref\" href=\"test2.html\">Hello World</a>", "Test XRef: @unknown_xref", "Test XRef: <a class=\"xref\" href=\"test2.html\"><img src=\".\"></a>", "Test link: <a href=\"test2.html\">link text</a>", "<p>", "test</p>", "", }, File.ReadAllLines(file)); file = Path.Combine(_outputFolder, Path.ChangeExtension(conceptualFile2, ".html")); Assert.True(File.Exists(file)); Assert.Equal <string>( new string[] { "", "<h1 id=\"hello-world\">Hello World</h1>", "<p>Test XRef: <a class=\"xref\" href=\"test1.html\">Hello Test1</a>", "Test XRef auto link: <a class=\"xref\" href=\"test1.html\">Hello Test1</a>", "Test link: <a href=\"test1.html\">link text</a>", "<p>", "test</p>", "" }, File.ReadAllLines(file)); }
private static int ExecSubCommand(string[] args) { var consoleLogListener = new ConsoleLogListener(); var replayListener = new ReplayLogListener(); replayListener.AddListener(consoleLogListener); Logger.RegisterListener(replayListener); CommandController controller = null; ISubCommand command; try { controller = ArgsParser.Instance.Parse(args); command = controller.Create(); } catch (System.IO.FileNotFoundException fe) { Logger.LogError(fe.Message); return(1); } catch (OptionParserException e) { Logger.LogError(e.Message); if (controller != null) { Console.WriteLine(controller.GetHelpText()); } return(1); } catch (Exception ex) { Logger.LogError(ex.ToString()); if (controller != null) { Console.WriteLine(controller.GetHelpText()); } return(1); } if (!(command is ILoggable)) { replayListener.Replay = false; } var context = new SubCommandRunningContext(); try { command.Exec(context); return(0); } catch (DocfxException de) { Logger.LogError(de.Message); return(1); } catch (Exception e) { Logger.LogError(e.ToString()); return(1); } }
public void LogTest() { var logger = new ConsoleLogListener(); Assert.DoesNotThrow(() => logger.Log(new LogMessage(LogLevel.Debug, "test"))); }