Browse Source

Add basic logging infrastructure

pull/848/head
Siegfried Pammer 8 years ago
parent
commit
59d7416813
  1. 26
      ICSharpCode.Decompiler/DecompilerEventSource.cs
  2. 2
      ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj
  3. 9
      ILSpy/Commands/SortAssemblyListCommand.cs
  4. 4
      ILSpy/ILSpy.csproj
  5. 13
      ILSpy/LogWindow.xaml
  6. 74
      ILSpy/LogWindow.xaml.cs
  7. 1
      ILSpy/TextView/DecompilerTextView.cs

26
ICSharpCode.Decompiler/DecompilerEventSource.cs

@ -0,0 +1,26 @@ @@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.Tracing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ICSharpCode.Decompiler.TypeSystem;
using ICSharpCode.Decompiler.TypeSystem.Implementation;
using Mono.Cecil;
namespace ICSharpCode.Decompiler
{
[EventSource(Name = "DecompilerEventSource")]
public sealed class DecompilerEventSource : EventSource
{
public static DecompilerEventSource Log = new DecompilerEventSource();
[Event(1, Level = EventLevel.Informational)]
public void Info(string text)
{
WriteEvent(1, text);
}
}
}

2
ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj

@ -46,6 +46,7 @@ @@ -46,6 +46,7 @@
<ItemGroup>
<PackageReference Include="System.Collections.Immutable" Version="1.3.0" />
<PackageReference Include="System.Diagnostics.Tracing" Version="4.3.0" />
<PackageReference Include="System.ValueTuple" Version="4.3.0" />
</ItemGroup>
@ -257,6 +258,7 @@ @@ -257,6 +258,7 @@
<Compile Include="Documentation\IdStringMemberReference.cs" />
<Compile Include="Documentation\IdStringProvider.cs" />
<Compile Include="Documentation\XmlDocumentationProvider.cs" />
<Compile Include="DecompilerEventSource.cs" />
<Compile Include="IL\ControlFlow\AsyncAwaitDecompiler.cs" />
<Compile Include="IL\ControlFlow\ControlFlowGraph.cs" />
<Compile Include="IL\ControlFlow\StateRangeAnalysis.cs" />

9
ILSpy/Commands/SortAssemblyListCommand.cs

@ -36,4 +36,13 @@ namespace ICSharpCode.ILSpy @@ -36,4 +36,13 @@ namespace ICSharpCode.ILSpy
return string.Compare(x.ShortName, y.ShortName, StringComparison.CurrentCulture);
}
}
[ExportMainMenuCommand(Menu = "_View", Header = "_Output", MenuIcon = "Images/ViewCode.png", MenuCategory = "View")]
sealed class ShowLog : SimpleCommand
{
public override void Execute(object parameter)
{
LogWindow.Instance.Show();
}
}
}

4
ILSpy/ILSpy.csproj

@ -126,6 +126,7 @@ @@ -126,6 +126,7 @@
<Compile Include="Languages\Language.cs" />
<Compile Include="Languages\Languages.cs" />
<Compile Include="LoadedAssembly.cs" />
<Compile Include="LogWindow.xaml.cs" />
<Compile Include="NativeMethods.cs" />
<Compile Include="NavigationHistory.cs" />
<Compile Include="NavigationState.cs" />
@ -303,6 +304,9 @@ @@ -303,6 +304,9 @@
<Page Include="SearchPane.xaml">
<DependentUpon>SearchPane.cs</DependentUpon>
</Page>
<Page Include="LogWindow.xaml">
<DependentUpon>LogWindow.xaml.cs</DependentUpon>
</Page>
<Page Include="TextView\DecompilerTextView.xaml">
<DependentUpon>DecompilerTextView.cs</DependentUpon>
</Page>

13
ILSpy/LogWindow.xaml

@ -0,0 +1,13 @@ @@ -0,0 +1,13 @@
<UserControl x:Class="ICSharpCode.ILSpy.LogWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:ICSharpCode.ILSpy"
xmlns:ae="http://icsharpcode.net/sharpdevelop/avalonedit"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<ae:TextEditor x:Name="log" FontFamily="Consolas" FontSize="10pt" IsReadOnly="True" />
</Grid>
</UserControl>

74
ILSpy/LogWindow.xaml.cs

@ -0,0 +1,74 @@ @@ -0,0 +1,74 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.Tracing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using ICSharpCode.AvalonEdit;
namespace ICSharpCode.ILSpy
{
partial class LogWindow : UserControl, IPane
{
static LogWindow instance;
public static LogWindow Instance {
get {
if (instance == null) {
App.Current.VerifyAccess();
instance = new LogWindow();
}
return instance;
}
}
readonly AvalonEditEventListener listener;
private LogWindow()
{
InitializeComponent();
this.listener = new AvalonEditEventListener(this.log);
}
public void Show()
{
if (!IsVisible) {
MainWindow.Instance.ShowInBottomPane("Output", this);
}
}
public void Closed()
{
}
class AvalonEditEventListener : EventListener
{
private TextEditor editor;
public AvalonEditEventListener(TextEditor editor)
{
this.editor = editor ?? throw new ArgumentNullException(nameof(editor));
}
protected override void OnEventSourceCreated(EventSource eventSource)
{
if (eventSource.Name == "DecompilerEventSource")
EnableEvents(eventSource, EventLevel.LogAlways, EventKeywords.All);
}
protected override void OnEventWritten(EventWrittenEventArgs eventData)
{
editor.Dispatcher.InvokeAsync(() => WriteToLog(eventData));
}
private void WriteToLog(EventWrittenEventArgs eventData)
{
editor.AppendText(eventData.Payload[0] + Environment.NewLine);
editor.ScrollToEnd();
}
}
}
}

1
ILSpy/TextView/DecompilerTextView.cs

@ -498,6 +498,7 @@ namespace ICSharpCode.ILSpy.TextView @@ -498,6 +498,7 @@ namespace ICSharpCode.ILSpy.TextView
if (i > 0)
textOutput.WriteLine();
DecompilerEventSource.Log.Info($"Decompilation started...");
context.Options.CancellationToken.ThrowIfCancellationRequested();
nodes[i].Decompile(context.Language, textOutput, context.Options);
}

Loading…
Cancel
Save