Example #1
0
        public static Invocation Create(
            bool emitMachineEnvironment          = false,
            bool emitTimestamps                  = true,
            IEnumerable <string> propertiesToLog = null)
        {
            var invocation = new Invocation
            {
                _suppressNonDeterministicProperties = !emitTimestamps,
                _propertiesToLog = propertiesToLog?.Select(p => p.ToUpperInvariant()).ToList()
            };

            if (emitTimestamps)
            {
                invocation.StartTimeUtc = DateTime.UtcNow;
            }

            if (invocation.ShouldLog(nameof(ProcessId)))
            {
                invocation.ProcessId = System.Diagnostics.Process.GetCurrentProcess().Id;
            }

            if (invocation.ShouldLog(nameof(WorkingDirectory)))
            {
                invocation.WorkingDirectory = new ArtifactLocation {
                    Uri = new Uri(Environment.CurrentDirectory)
                };
            }

            if (invocation.ShouldLog(nameof(CommandLine)))
            {
                invocation.CommandLine = Environment.CommandLine;
            }

            if (emitMachineEnvironment)
            {
                invocation.Machine = Environment.MachineName;
                invocation.Account = Environment.UserName;
                invocation.EnvironmentVariables = CopyEnvironmentVariables();
            }

            if (invocation.ShouldLog(nameof(ExecutableLocation)))
            {
                Assembly assembly = Assembly.GetEntryAssembly() ?? Assembly.GetExecutingAssembly();
                invocation.ExecutableLocation.Uri = new Uri(assembly.Location);
            }

            invocation.ExecutionSuccessful = true;

            return(invocation);
        }
Example #2
0
        public static Invocation Create(
            bool emitMachineEnvironment          = false,
            IEnumerable <string> propertiesToLog = null)
        {
            var invocation = new Invocation
            {
                PropertiesToLog = propertiesToLog?.Select(p => p.ToUpperInvariant()).ToList()
            };

            invocation.StartTime = DateTime.UtcNow;

            if (invocation.ShouldLog(nameof(ProcessId)))
            {
                invocation.ProcessId = System.Diagnostics.Process.GetCurrentProcess().Id;
            }

            if (invocation.ShouldLog(nameof(WorkingDirectory)))
            {
                invocation.WorkingDirectory = Environment.CurrentDirectory;
            }

            if (invocation.ShouldLog(nameof(CommandLine)))
            {
                invocation.CommandLine = Environment.CommandLine;
            }

            if (emitMachineEnvironment)
            {
                invocation.Machine = Environment.MachineName;
                invocation.Account = Environment.UserName;
                invocation.EnvironmentVariables = CopyEnvironmentVariables();
            }

            if (invocation.ShouldLog(nameof(FileName)))
            {
                Assembly assembly = Assembly.GetEntryAssembly() ?? Assembly.GetExecutingAssembly();
                invocation.FileName = assembly.Location;
            }

            return(invocation);
        }