mirror of
https://github.com/ckaczor/WorkIndicator.git
synced 2026-01-13 17:23:18 -05:00
Add some basic logging
This commit is contained in:
10
App.xaml.cs
10
App.xaml.cs
@@ -1,6 +1,7 @@
|
|||||||
using Common.Helpers;
|
using Common.Helpers;
|
||||||
using Common.IO;
|
using Common.IO;
|
||||||
using Common.Wpf.Extensions;
|
using Common.Wpf.Extensions;
|
||||||
|
using Serilog;
|
||||||
using Squirrel;
|
using Squirrel;
|
||||||
using System;
|
using System;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
@@ -25,6 +26,13 @@ namespace WorkIndicator
|
|||||||
{
|
{
|
||||||
SquirrelAwareApp.HandleEvents(onAppUpdate: version => Common.Settings.Extensions.RestoreSettings());
|
SquirrelAwareApp.HandleEvents(onAppUpdate: version => Common.Settings.Extensions.RestoreSettings());
|
||||||
|
|
||||||
|
Log.Logger = new LoggerConfiguration()
|
||||||
|
.MinimumLevel.Debug()
|
||||||
|
.WriteTo.File("log.txt", rollingInterval: RollingInterval.Day)
|
||||||
|
.CreateLogger();
|
||||||
|
|
||||||
|
Log.Logger.Debug($"Startup");
|
||||||
|
|
||||||
var application = new App();
|
var application = new App();
|
||||||
application.InitializeComponent();
|
application.InitializeComponent();
|
||||||
application.Run();
|
application.Run();
|
||||||
@@ -90,6 +98,8 @@ namespace WorkIndicator
|
|||||||
|
|
||||||
protected override void OnExit(ExitEventArgs e)
|
protected override void OnExit(ExitEventArgs e)
|
||||||
{
|
{
|
||||||
|
Log.Logger.Debug($"Exit");
|
||||||
|
|
||||||
// Get rid of the light controller
|
// Get rid of the light controller
|
||||||
LightController.Dispose();
|
LightController.Dispose();
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using CSCore.CoreAudioAPI;
|
using CSCore.CoreAudioAPI;
|
||||||
|
using Serilog;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@@ -20,8 +21,12 @@ namespace WorkIndicator
|
|||||||
|
|
||||||
private static readonly List<AudioSessionManager2> _sessionManagers = new List<AudioSessionManager2>();
|
private static readonly List<AudioSessionManager2> _sessionManagers = new List<AudioSessionManager2>();
|
||||||
|
|
||||||
|
private static readonly ILogger Logger = Log.Logger;
|
||||||
|
|
||||||
public static void Start()
|
public static void Start()
|
||||||
{
|
{
|
||||||
|
Logger.Debug("AudioWatcher - Start");
|
||||||
|
|
||||||
_manualResetEvent = new ManualResetEvent(false);
|
_manualResetEvent = new ManualResetEvent(false);
|
||||||
|
|
||||||
_thread = new Thread(delegate ()
|
_thread = new Thread(delegate ()
|
||||||
@@ -34,11 +39,9 @@ namespace WorkIndicator
|
|||||||
|
|
||||||
_sessionManagers.Add(sessionManager);
|
_sessionManagers.Add(sessionManager);
|
||||||
|
|
||||||
var sessionEnumerator = sessionManager.GetSessionEnumerator();
|
|
||||||
|
|
||||||
sessionManager.SessionCreated += (sessionSender, sessionCreatedEventArgs) => HandleDeviceSession(device, sessionCreatedEventArgs.NewSession);
|
sessionManager.SessionCreated += (sessionSender, sessionCreatedEventArgs) => HandleDeviceSession(device, sessionCreatedEventArgs.NewSession);
|
||||||
|
|
||||||
foreach (var audioSessionControl in sessionEnumerator)
|
foreach (var audioSessionControl in sessionManager.GetSessionEnumerator())
|
||||||
{
|
{
|
||||||
HandleDeviceSession(device, audioSessionControl);
|
HandleDeviceSession(device, audioSessionControl);
|
||||||
}
|
}
|
||||||
@@ -55,6 +58,8 @@ namespace WorkIndicator
|
|||||||
{
|
{
|
||||||
var deviceId = device.DeviceID + audioSessionControl.GroupingParam;
|
var deviceId = device.DeviceID + audioSessionControl.GroupingParam;
|
||||||
|
|
||||||
|
Logger.Debug($"AudioWatcher - HandleDeviceSession - {device.FriendlyName}, {deviceId}");
|
||||||
|
|
||||||
if (!ActiveSessions.ContainsKey(deviceId))
|
if (!ActiveSessions.ContainsKey(deviceId))
|
||||||
ActiveSessions[deviceId] = 0;
|
ActiveSessions[deviceId] = 0;
|
||||||
|
|
||||||
@@ -66,6 +71,8 @@ namespace WorkIndicator
|
|||||||
|
|
||||||
public static void Stop()
|
public static void Stop()
|
||||||
{
|
{
|
||||||
|
Logger.Debug("AudioWatcher - Stop");
|
||||||
|
|
||||||
_sessionManagers.Clear();
|
_sessionManagers.Clear();
|
||||||
|
|
||||||
_manualResetEvent?.Set();
|
_manualResetEvent?.Set();
|
||||||
@@ -73,6 +80,8 @@ namespace WorkIndicator
|
|||||||
|
|
||||||
private static void HandleAudioStateChanged(string deviceId, AudioSessionState newState)
|
private static void HandleAudioStateChanged(string deviceId, AudioSessionState newState)
|
||||||
{
|
{
|
||||||
|
Logger.Debug($"AudioWatcher - HandleAudioStateChanged - {deviceId}, {newState}");
|
||||||
|
|
||||||
switch (newState)
|
switch (newState)
|
||||||
{
|
{
|
||||||
case AudioSessionState.AudioSessionStateActive:
|
case AudioSessionState.AudioSessionStateActive:
|
||||||
@@ -83,11 +92,14 @@ namespace WorkIndicator
|
|||||||
ActiveSessions[deviceId]--;
|
ActiveSessions[deviceId]--;
|
||||||
break;
|
break;
|
||||||
case AudioSessionState.AudioSessionStateExpired:
|
case AudioSessionState.AudioSessionStateExpired:
|
||||||
|
ActiveSessions[deviceId] = 0;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new ArgumentOutOfRangeException();
|
throw new ArgumentOutOfRangeException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Logger.Debug($"AudioWatcher - HandleAudioStateChanged - {deviceId} = {ActiveSessions[deviceId]}");
|
||||||
|
|
||||||
MicrophoneInUseChanged?.Invoke(MicrophoneInUse());
|
MicrophoneInUseChanged?.Invoke(MicrophoneInUse());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -238,6 +238,12 @@
|
|||||||
<PackageReference Include="Newtonsoft.Json">
|
<PackageReference Include="Newtonsoft.Json">
|
||||||
<Version>13.0.1</Version>
|
<Version>13.0.1</Version>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
|
<PackageReference Include="Serilog">
|
||||||
|
<Version>2.10.0</Version>
|
||||||
|
</PackageReference>
|
||||||
|
<PackageReference Include="Serilog.Sinks.File">
|
||||||
|
<Version>5.0.0</Version>
|
||||||
|
</PackageReference>
|
||||||
<PackageReference Include="squirrel.windows">
|
<PackageReference Include="squirrel.windows">
|
||||||
<Version>2.0.1</Version>
|
<Version>2.0.1</Version>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
|
|||||||
Reference in New Issue
Block a user