Skip to content

Commit

Permalink
Add TraceListener to enable logging to trace channel using Trace.Writ…
Browse files Browse the repository at this point in the history
…eLine().
  • Loading branch information
rinrab committed Jan 10, 2024
1 parent f8d24ea commit 6ad674d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
24 changes: 24 additions & 0 deletions AOVpnManager/EventSourceTraceListener.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System.Diagnostics;

namespace AOVpnManager
{
public class EventSourceTraceListener : TraceListener
{
private readonly ILogger logger;

public EventSourceTraceListener(ILogger logger) : base()
{
this.logger = logger;
}

public override void Write(string message)
{
logger.Trace(message);
}

public override void WriteLine(string message)
{
logger.Trace(message);
}
}
}
3 changes: 3 additions & 0 deletions AOVpnManager/Program.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Microsoft.Win32;
using System;
using System.Diagnostics;

namespace AOVpnManager
{
Expand All @@ -13,6 +14,8 @@ static int Main(string[] args)
IGroupPolicyProvider policyProvider = new GroupPolicyProvider(Registry.LocalMachine, @"SOFTWARE\Policies\AOVpnManager");
IStateManager stateManager = new StateManager(Registry.LocalMachine, @"SOFTWARE\AOVpnManager");

Trace.Listeners.Add(new EventSourceTraceListener(logger));

logger.Started();
int exitCode = 0;

Expand Down

0 comments on commit 6ad674d

Please sign in to comment.