/
MSBuildFileLogger.cs
106 lines (91 loc) · 4.74 KB
/
MSBuildFileLogger.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Collections.Generic;
using System.Linq;
using Cake.Core;
using Cake.Core.Diagnostics;
using Cake.Core.IO;
namespace Cake.Common.Tools.MSBuild
{
/// <summary>
/// Contains settings for specifying a MSBuild file logger.
/// </summary>
public class MSBuildFileLogger
{
/// <summary>
/// Initializes a new instance of the <see cref="MSBuildFileLogger"/> class.
/// </summary>
public MSBuildFileLogger()
{
}
/// <summary>
/// Gets or sets a value indicating whether PerformanceSummary will Show the time that’s spent in tasks, targets, and projects.
/// </summary>
public bool PerformanceSummaryEnabled { get; set; }
/// <summary>
/// Gets or sets a value indicating whether Summary will Show the error and warning summary at the end.
/// </summary>
public bool SummaryDisabled { get; set; }
/// <summary>
/// Gets or sets show ErrorsOnly, WarningsOnly, or All.
/// </summary>
public MSBuildFileLoggerOutput MSBuildFileLoggerOutput { get; set; }
/// <summary>
/// Gets or sets a value indicating whether NoItemAndPropertyList will be set to Don't show the list of items and properties that would appear at the start of each project build if the verbosity level is set to diagnostic.
/// </summary>
public bool HideVerboseItemAndPropertyList { get; set; }
/// <summary>
/// Gets or sets a value indicating whether ShowCommandLine. Show TaskCommandLineEvent messages.
/// </summary>
public bool ShowCommandLine { get; set; }
/// <summary>
/// Gets or sets a value indicating whether ShowTimestamp. Show the timestamp as a prefix to any message.
/// </summary>
public bool ShowTimestamp { get; set; }
/// <summary>
/// Gets or sets a value indicating whether ShowEventId. Show the event ID for each started event, finished event, and message.
/// </summary>
public bool ShowEventId { get; set; }
/// <summary>
/// Gets or sets Verbosity. Override the /verbosity setting for this logger.
/// Specify the following verbosity levels: q[uiet], m[inimal], n[ormal], v[erbose] (detailed), and diag[nostic].
/// </summary>
public Verbosity? Verbosity { get; set; }
/// <summary>
/// Gets or sets LogFile. The path to the log file into which the build log is written.
/// An empty string will use msbuild.log.
/// </summary>
public FilePath LogFile { get; set; }
/// <summary>
/// Gets or sets a value indicating whether the build log is appended to the log file or overwrites it. When true, the build log is appended to the log file.
/// </summary>
public bool AppendToLogFile { get; set; }
/// <summary>
/// Gets or sets Specifies the encoding for the file (for example, UTF-8, Unicode, or ASCII).
/// </summary>
public string Encoding { get; set; }
/// <summary>
/// Process the file logger config and return parameters as a string.
/// </summary>
/// <param name="environment">The environment.</param>
/// <returns>The parameters separated by semi-colons.</returns>
public string GetParameters(ICakeEnvironment environment)
{
var parameters = new List<string>();
parameters.Add(LogFile != null ? $"logfile={LogFile.MakeAbsolute(environment).FullPath.Quote()}" : null);
parameters.Add(!string.IsNullOrWhiteSpace(Encoding) ? $"Encoding={Encoding}" : null);
parameters.Add(AppendToLogFile ? "Append" : null);
parameters.Add(PerformanceSummaryEnabled ? "PerformanceSummary" : null);
parameters.Add(SummaryDisabled ? "NoSummary" : null);
parameters.Add(MSBuildFileLoggerOutput == MSBuildFileLoggerOutput.ErrorsOnly ? "ErrorsOnly" : null);
parameters.Add(MSBuildFileLoggerOutput == MSBuildFileLoggerOutput.WarningsOnly ? "WarningsOnly" : null);
parameters.Add(HideVerboseItemAndPropertyList ? "NoItemAndPropertyList" : null);
parameters.Add(ShowCommandLine ? "ShowCommandLine" : null);
parameters.Add(ShowTimestamp ? "ShowTimestamp" : null);
parameters.Add(ShowEventId ? "ShowEventId" : null);
parameters.Add(Verbosity != null ? $"Verbosity={Verbosity.Value.GetMSBuildVerbosityName()}" : null);
return string.Join(";", parameters.Where(p => p != null));
}
}
}