Terminal logger
This commit is contained in:
@@ -1,7 +1,9 @@
|
|||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
using System.Threading.Channels;
|
||||||
using Microsoft.Build.Execution;
|
using Microsoft.Build.Execution;
|
||||||
using Microsoft.Build.Framework;
|
using Microsoft.Build.Framework;
|
||||||
using Microsoft.Build.Logging;
|
using Microsoft.Build.Logging;
|
||||||
|
using SharpIDE.Application.Features.Logging;
|
||||||
|
|
||||||
namespace SharpIDE.Application.Features.Build;
|
namespace SharpIDE.Application.Features.Build;
|
||||||
|
|
||||||
@@ -14,6 +16,7 @@ public enum BuildType
|
|||||||
}
|
}
|
||||||
public class BuildService
|
public class BuildService
|
||||||
{
|
{
|
||||||
|
public Channel<string> BuildOutputChannel { get; } = Channel.CreateUnbounded<string>();
|
||||||
public async Task MsBuildSolutionAsync(string solutionFilePath, BuildType buildType = BuildType.Build)
|
public async Task MsBuildSolutionAsync(string solutionFilePath, BuildType buildType = BuildType.Build)
|
||||||
{
|
{
|
||||||
var buildParameters = new BuildParameters
|
var buildParameters = new BuildParameters
|
||||||
@@ -21,7 +24,8 @@ public class BuildService
|
|||||||
Loggers =
|
Loggers =
|
||||||
[
|
[
|
||||||
//new BinaryLogger { Parameters = "msbuild.binlog" },
|
//new BinaryLogger { Parameters = "msbuild.binlog" },
|
||||||
new ConsoleLogger(LoggerVerbosity.Quiet),
|
new ConsoleLogger(LoggerVerbosity.Normal, message => BuildOutputChannel.Writer.TryWrite(message), s => { }, () => { }),
|
||||||
|
//new InMemoryLogger(LoggerVerbosity.Normal)
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
string[] targetsToBuild = buildType switch
|
string[] targetsToBuild = buildType switch
|
||||||
|
|||||||
36
src/SharpIDE.Application/Features/Logging/InMemoryLogger.cs
Normal file
36
src/SharpIDE.Application/Features/Logging/InMemoryLogger.cs
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
using Microsoft.Build.Framework;
|
||||||
|
using Microsoft.Build.Utilities;
|
||||||
|
|
||||||
|
namespace SharpIDE.Application.Features.Logging;
|
||||||
|
|
||||||
|
public sealed class InMemoryLogger : Logger
|
||||||
|
{
|
||||||
|
public InMemoryLogger(LoggerVerbosity verbosity)
|
||||||
|
{
|
||||||
|
Verbosity = verbosity;
|
||||||
|
}
|
||||||
|
public override void Initialize(IEventSource eventSource)
|
||||||
|
{
|
||||||
|
//Register for the ProjectStarted, TargetStarted, and ProjectFinished events
|
||||||
|
eventSource.ProjectStarted += new ProjectStartedEventHandler(eventSource_ProjectStarted);
|
||||||
|
eventSource.TargetStarted += new TargetStartedEventHandler(eventSource_TargetStarted);
|
||||||
|
eventSource.ProjectFinished += new ProjectFinishedEventHandler(eventSource_ProjectFinished);
|
||||||
|
}
|
||||||
|
|
||||||
|
void eventSource_ProjectStarted(object sender, ProjectStartedEventArgs e)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Project Started: " + e.ProjectFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
void eventSource_ProjectFinished(object sender, ProjectFinishedEventArgs e)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Project Finished: " + e.ProjectFile);
|
||||||
|
}
|
||||||
|
void eventSource_TargetStarted(object sender, TargetStartedEventArgs e)
|
||||||
|
{
|
||||||
|
if (Verbosity == LoggerVerbosity.Detailed)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Target Started: " + e.TargetName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
21
src/SharpIDE.Photino/Components/TerminalOutputDisplay.razor
Normal file
21
src/SharpIDE.Photino/Components/TerminalOutputDisplay.razor
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
@using SharpIDE.Application.Features.Build
|
||||||
|
@inject BuildService BuildService
|
||||||
|
|
||||||
|
<div style="height: 15rem; overflow-y: auto; padding: 1rem; background-color: #303030; border: 1px solid #ccc;">
|
||||||
|
@foreach(var line in _outputLines)
|
||||||
|
{
|
||||||
|
<MudText Typo="Typo.body2">@line</MudText>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@code {
|
||||||
|
private List<string> _outputLines = [];
|
||||||
|
protected override async Task OnInitializedAsync()
|
||||||
|
{
|
||||||
|
await foreach (var logLine in BuildService.BuildOutputChannel.Reader.ReadAllAsync())
|
||||||
|
{
|
||||||
|
_outputLines.Add(logLine);
|
||||||
|
await InvokeAsync(StateHasChanged);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -35,6 +35,7 @@
|
|||||||
<CodeViewer SelectedFile="@_selectedFile" />
|
<CodeViewer SelectedFile="@_selectedFile" />
|
||||||
}
|
}
|
||||||
</MudContainer>
|
</MudContainer>
|
||||||
|
<TerminalOutputDisplay />
|
||||||
</MudMainContent>
|
</MudMainContent>
|
||||||
</MudLayout>
|
</MudLayout>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user