Skip to content

Commit

Permalink
Improve logging
Browse files Browse the repository at this point in the history
  • Loading branch information
Antoine Aflalo committed Feb 26, 2017
1 parent dae19a3 commit 44b6184
Showing 1 changed file with 26 additions and 18 deletions.
44 changes: 26 additions & 18 deletions SoundSwitch/Model/AudioDeviceLister.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,19 +75,22 @@ private void AudioControllerOnDeviceAdded(object sender, DeviceAddedEvent device
/// <returns></returns>
public ICollection<IAudioDevice> GetPlaybackDevices()
{
_cacheLock.EnterUpgradeableReadLock();
try
using (AppLogger.Log.DebugCall())
{
if (_needUpdate)
_cacheLock.EnterUpgradeableReadLock();
try
{
if (!_needUpdate) return _playback;

AppLogger.Log.Debug("Needs update");
Refresh();
return _playback;
}
finally
{
AppLogger.Log.Debug("Get Playback Devices");
_cacheLock.ExitUpgradeableReadLock();
}
return _playback;
}
finally
{
AppLogger.Log.Debug("Get Playback Devices");
_cacheLock.ExitUpgradeableReadLock();
}


Expand All @@ -102,6 +105,7 @@ private void Refresh()

try
{
AppLogger.Log.Debug("Refreshing playback devices");
_playback.UnionWith(AudioController.GetPlaybackDevices(_state));
}
catch (DefSoundException e)
Expand All @@ -113,6 +117,7 @@ private void Refresh()
_recording.Clear();
try
{
AppLogger.Log.Debug("Refreshing recording devices");
_recording.UnionWith(AudioController.GetRecordingDevices(_state));
}
catch (DefSoundException e)
Expand All @@ -133,19 +138,22 @@ private void Refresh()
/// <returns></returns>
public ICollection<IAudioDevice> GetRecordingDevices()
{
_cacheLock.EnterUpgradeableReadLock();
try
using (AppLogger.Log.DebugCall())
{
if (_needUpdate)
_cacheLock.EnterUpgradeableReadLock();
try
{
if (!_needUpdate) return _recording;

AppLogger.Log.Debug("Needs update");
Refresh();
return _recording;
}
finally
{
AppLogger.Log.Debug("Get Recording Devices");
_cacheLock.ExitUpgradeableReadLock();
}
return _recording;
}
finally
{
AppLogger.Log.Debug("Get Recording Devices");
_cacheLock.ExitUpgradeableReadLock();
}
}
}
Expand Down

0 comments on commit 44b6184

Please sign in to comment.