Exemple #1
0
        /// <summary>
        /// Logs information about the extractor, as well as the arguments to Roslyn.
        /// </summary>
        /// <param name="roslynArgs">The arguments passed to Roslyn.</param>
        /// <returns>A Boolean indicating whether the same arguments have been logged previously.</returns>
        public bool LogRoslynArgs(string[] roslynArgs, string extractorVersion)
        {
            LogExtractorInfo(extractorVersion);
            Logger.Log(Severity.Info, $"  Arguments to Roslyn: {string.Join(' ', roslynArgs)}");

            var csharpLogDir = Extractor.GetCSharpLogDirectory();
            var tempFile     = Path.Combine(csharpLogDir, $"csharp.{Path.GetRandomFileName()}.txt");

            bool argsWritten;

            using (var streamWriter = new StreamWriter(new FileStream(tempFile, FileMode.Append, FileAccess.Write)))
            {
                streamWriter.WriteLine($"# Arguments to Roslyn: {string.Join(' ', roslynArgs.Where(arg => !arg.StartsWith('@')))}");
                argsWritten = roslynArgs.WriteCommandLine(streamWriter);
            }

            var hash     = FileUtils.ComputeFileHash(tempFile);
            var argsFile = Path.Combine(csharpLogDir, $"csharp.{hash}.txt");

            if (argsWritten)
            {
                Logger.Log(Severity.Info, $"  Arguments have been written to {argsFile}");
            }

            if (File.Exists(argsFile))
            {
                try
                {
                    File.Delete(tempFile);
                }
                catch (IOException e)
                {
                    Logger.Log(Severity.Warning, $"  Failed to remove {tempFile}: {e.Message}");
                }
                return(false);
            }

            try
            {
                File.Move(tempFile, argsFile);
            }
            catch (IOException e)
            {
                Logger.Log(Severity.Warning, $"  Failed to move {tempFile} to {argsFile}: {e.Message}");
            }

            return(true);
        }
Exemple #2
0
        /// <summary>
        /// Logs detailed information about this invocation,
        /// in the event that errors were detected.
        /// </summary>
        /// <param name="roslynArgs">The arguments passed to Roslyn.</param>
        public void LogDiagnostics(string[] roslynArgs)
        {
            Logger.Log(Severity.Info, "  Extractor: {0}", Environment.GetCommandLineArgs().First());
            if (extractor != null)
            {
                Logger.Log(Severity.Info, "  Extractor version: {0}", extractor.Version);
            }

            Logger.Log(Severity.Info, "  Current working directory: {0}", Directory.GetCurrentDirectory());

            if (roslynArgs != null)
            {
                Logger.Log(Severity.Info, $"  Arguments to Roslyn: {string.Join(' ', roslynArgs)}");

                // Create a new file in the log folder.
                var argsFile = Path.Combine(Extractor.GetCSharpLogDirectory(), $"csharp.{Path.GetRandomFileName()}.txt");

                if (roslynArgs.ArchiveCommandLine(argsFile))
                {
                    Logger.Log(Severity.Info, $"  Arguments have been written to {argsFile}");
                }
            }

            foreach (var error in FilteredDiagnostics)
            {
                Logger.Log(Severity.Error, "  Compilation error: {0}", error);
            }

            if (FilteredDiagnostics.Any())
            {
                foreach (var reference in compilation.References)
                {
                    Logger.Log(Severity.Info, "  Resolved reference {0}", reference.Display);
                }
            }
        }