Skip to content

Commit

Permalink
Added to latest version of Serilog and added Console Sink
Browse files Browse the repository at this point in the history
When running in Visual Studio and debugging the component the console will now be populated with the logs that are created during the run.
  • Loading branch information
ByronMayne committed Nov 12, 2023
1 parent 0521915 commit 2b13f3f
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ namespace SGF.Interop.VisualStudio
{
public class VisualStudioLogEventSink : ILogEventSink
{
const string outputPanelName = "Source Generators";
const string DefaultOutputTemplate = "[{Timestamp:HH:mm:ss} {Level:u3}] {SourceContext} | {Message:lj}{NewLine}{Exception}";
private const string outputPanelName = "Source Generators";
private const string DefaultOutputTemplate = "{Timestamp:HH:mm:ss} {SourceContext} | {Message:lj}{NewLine}{Exception}";

private static readonly DTE? s_dte;
private static readonly OutputWindow? s_outputWindow;
Expand Down Expand Up @@ -72,11 +72,9 @@ public void Emit(LogEvent logEvent)
{
if (m_outputInitialized)
{
using (StringWriter stringWriter = new StringWriter())
{
m_templateFormatter.Format(logEvent, stringWriter);
m_outputPane!.OutputString(stringWriter.ToString());
}
using StringWriter stringWriter = new();
m_templateFormatter.Format(logEvent, stringWriter);
m_outputPane!.OutputString(stringWriter.ToString());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.Interop" Version="17.4.33103.184" GeneratePathProperty="true" PrivateAssets="all" />
<PackageReference Include="Serilog" Version="3.1.1" />
<PackageReference Include="System.Management" Version="7.0.0" GeneratePathProperty="true" />
</ItemGroup>
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.3.1" PrivateAssets="all" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
<PackageReference Include="Serilog" Version="3.1.1" />
</ItemGroup>
<Import Project="..\..\Local.Reference.props" />
</Project>
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Serilog;
using SGF.Sinks;
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
Expand Down Expand Up @@ -42,10 +41,14 @@ static DevelopmentEnviroment()
Directory.CreateDirectory(TempDirectory);
}

Logger = new LoggerConfiguration()
.WriteTo.Sink(s_sinkAggregate)
.CreateLogger();
LoggerConfiguration configuration = new LoggerConfiguration()
.WriteTo.Sink(s_sinkAggregate);

if (Environment.UserInteractive)
{
configuration.WriteTo.Console();
}
Logger = configuration.CreateLogger();
string assemblyVersion
= typeof(DevelopmentEnviroment)
.Assembly
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Serilog" Version="3.1.1" />
<PackageReference Include="Serilog.Sinks.Console" Version="5.0.0" />
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
</ItemGroup>
<!--<Target Name="SGF_AddPluginDependedencies" BeforeTargets="SGF_EmbedDependencies">
Expand Down

0 comments on commit 2b13f3f

Please sign in to comment.