diff --git a/AntPlus.Extensions.Hosting/AntCollection.cs b/AntPlus.Extensions.Hosting/AntCollection.cs index 9e7a9069..5b2c42e0 100644 --- a/AntPlus.Extensions.Hosting/AntCollection.cs +++ b/AntPlus.Extensions.Hosting/AntCollection.cs @@ -91,12 +91,12 @@ private void MessageHandler(object? sender, AntResponse e) // re-open the channel in scan mode if (_antRadio is IAntControl antControl) { - _logger.LogWarning("Re-opening channel 0 in scan mode."); + _logger.LogWarning(new EventId(1012, "MessageHandler"), "AntRadio #{SerialNumber}: Re-opening channel 0 in scan mode.", _antRadio.SerialNumber); _ = antControl.OpenRxScanMode(); } else { - _logger.LogCritical("IAntControl not implemented. Can't re-open channel 0."); + _logger.LogCritical(new EventId(1013, "MessageHandler"), "AntRadio #{SerialNumber}: IAntControl not implemented. Can't re-open channel 0.", _antRadio.SerialNumber); } break; case MessageId.BroadcastData: diff --git a/AntPlus.Extensions.Hosting/Hosting.csproj b/AntPlus.Extensions.Hosting/Hosting.csproj index 8cf77758..718fe5be 100644 --- a/AntPlus.Extensions.Hosting/Hosting.csproj +++ b/AntPlus.Extensions.Hosting/Hosting.csproj @@ -17,11 +17,12 @@ PackageLogo.png readme.md - 1. Dispose AntDevices when AntCollection is disposed. - + 1. Improved logging messages for better debugging and monitoring of ANT+ device interactions. + 2. Updated NuGet package dependencies. + True snupkg - 2.0.8 + 2.0.9 https://stephenhidem.github.io/AntPlus https://github.com/StephenHidem/AntPlus Debug;Release @@ -42,7 +43,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/AntPlus.UnitTests/AntPlus.UnitTests.csproj b/AntPlus.UnitTests/AntPlus.UnitTests.csproj index f55442b9..8a3fa33b 100644 --- a/AntPlus.UnitTests/AntPlus.UnitTests.csproj +++ b/AntPlus.UnitTests/AntPlus.UnitTests.csproj @@ -10,7 +10,7 @@ - + all diff --git a/AntPlus/AntDeviceCollection.cs b/AntPlus/AntDeviceCollection.cs index acd94195..ccac9954 100644 --- a/AntPlus/AntDeviceCollection.cs +++ b/AntPlus/AntDeviceCollection.cs @@ -102,12 +102,12 @@ private void MessageHandler(object? sender, AntResponse e) // re-open the channel in scan mode if (_antRadio is IAntControl antControl) { - _logger.LogError("Re-opening channel 0 in scan mode."); + _logger.LogError(new EventId(1012, "MessageHandler"), "AntRadio #{SerialNumber}: Re-opening channel 0 in scan mode.", _antRadio.SerialNumber); _ = antControl.OpenRxScanMode(); } else { - _logger.LogCritical("IAntControl not implemented. Can't re-open channel 0."); + _logger.LogCritical(new EventId(1013, "MessageHandler"), "AntRadio #{SerialNumber}: IAntControl not implemented. Can't re-open channel 0.", _antRadio.SerialNumber); } break; case MessageId.BroadcastData: diff --git a/AntPlus/AntPlus.csproj b/AntPlus/AntPlus.csproj index 53959c2a..aec3802b 100644 --- a/AntPlus/AntPlus.csproj +++ b/AntPlus/AntPlus.csproj @@ -5,7 +5,7 @@ True SmallEarthTech.$(MSBuildProjectName.Replace(" ", "_")) SmallEarthTech.$(AssemblyName) - 7.0.0 + 7.0.1 ANT+ Class Library https://stephenhidem.github.io/AntPlus Stephen Hidem @@ -23,9 +23,7 @@ PackageLogo.png readme.md - 1. Breaking change: AntDeviceCollection is now disposable and implements IDisposable. This allows for proper cleanup of resources when the collection is no longer needed. Make sure to dispose of AntDeviceCollection instances to avoid memory leaks. - 2. Breaking change: Several public method signatures in LoggerExtensions have been changed to include the DeviceNumber parameter. This change was made to provide more context when working with multiple devices. You will need to update your code to include the DeviceNumber parameter when calling these methods. - 3. Updated NuGet dependencies. + 1. Improved logging messages for better debugging and monitoring of ANT+ device interactions. Debug;Release diff --git a/AntPlus/Extensions/Logging/LoggerExtensions.cs b/AntPlus/Extensions/Logging/LoggerExtensions.cs index ee3d8a2f..f0bde3fd 100644 --- a/AntPlus/Extensions/Logging/LoggerExtensions.cs +++ b/AntPlus/Extensions/Logging/LoggerExtensions.cs @@ -32,7 +32,7 @@ public static void LogUnknownDataPage(this ILogger logger, byte[] dataPage, uint s_unknownDataPage(logger, deviceNumber, dataPage[0], BitConverter.ToString(dataPage)); } - [LoggerMessage(EventId = 1000, Level = LogLevel.Warning, Message = "DeviceNumber={DeviceNumber}: Unknown data page# 0x{Page:X2}, Data page = {DataPage}")] + [LoggerMessage(EventId = 1000, EventName = "UnknownDataPage", Level = LogLevel.Warning, Message = "DeviceNumber={DeviceNumber}: Unknown data page# 0x{Page:X2}, Data page = {DataPage}")] private static partial void s_unknownDataPage(ILogger logger, uint deviceNumber, byte page, string dataPage); /// @@ -48,7 +48,7 @@ public static void LogUnknownDataPage(this ILogger logger, int pageIndex, s_unknownDataPageEnum(logger, deviceNumber, pageIndex, typeof(TEnum).Name, BitConverter.ToString(dataPage)); } - [LoggerMessage(EventId = 1001, Level = LogLevel.Warning, Message = "DeviceNumber={DeviceNumber}: Enum value at index {Index} is not defined in {Enum}, Data page = {DataPage}")] + [LoggerMessage(EventId = 1001, EventName = "UnknownDataPageEnum", Level = LogLevel.Warning, Message = "DeviceNumber={DeviceNumber}: Enum value at index {Index} is not defined in {Enum}, Data page = {DataPage}")] private static partial void s_unknownDataPageEnum(ILogger logger, uint deviceNumber, int index, string @enum, string dataPage); /// @@ -72,10 +72,10 @@ public static void LogSendAcknowledgedMessage(this ILogger logger, int channelIn } } - [LoggerMessage(EventId = 1002, Level = LogLevel.Debug, Message = "{MethodName}: Channel index = {ChannelIndex}, Channel ID = 0x{ChannelId:X8}, Page# 0x{Page:X2}, Data page = {DataPage}")] + [LoggerMessage(EventId = 1002, EventName = "SendAcknowledgedMessage", Level = LogLevel.Debug, Message = "{MethodName}: Channel index = {ChannelIndex}, Channel ID = 0x{ChannelId:X8}, Page# 0x{Page:X2}, Data page = {DataPage}")] private static partial void s_sendAckMsg(ILogger logger, string methodName, int channelIndex, uint channelId, byte page, string dataPage); - [LoggerMessage(EventId = 1003, Level = LogLevel.Debug, Message = "{MethodName}: Channel index = {ChannelIndex}, Channel ID = 0x{ChannelId:X8}, Page# 0x{Page:X2}, Result = {Result}")] + [LoggerMessage(EventId = 1003, EventName = "SendAcknowledgedMessageResult", Level = LogLevel.Debug, Message = "{MethodName}: Channel index = {ChannelIndex}, Channel ID = 0x{ChannelId:X8}, Page# 0x{Page:X2}, Result = {Result}")] private static partial void s_sendAckMsgResult(ILogger logger, string methodName, int channelIndex, uint channelId, byte page, MessagingReturnCode result); /// @@ -88,7 +88,7 @@ public static void LogMethodEntry(this ILogger logger, [CallerMemberName] string s_logMethodEntry(logger, methodName); } - [LoggerMessage(EventId = 1004, Level = LogLevel.Debug, Message = "Entering {MethodName}")] + [LoggerMessage(EventId = 1004, EventName = "MethodEntry", Level = LogLevel.Debug, Message = "Entering {MethodName}")] private static partial void s_logMethodEntry(ILogger logger, string methodName); /// @@ -103,7 +103,7 @@ public static void LogAntDeviceState(this ILogger logger, AntDevice antDevice, i s_logAntDeviceState(logger, methodName, antDevice, antDevice.ChannelId.DeviceNumber, antDevice.Offline, timeout); } - [LoggerMessage(EventId = 1005, Level = LogLevel.Debug, Message = "{MethodName} {AntDevice} Device# {DeviceNumber}, Offline = {Offline}, Timeout = {Timeout}ms")] + [LoggerMessage(EventId = 1005, EventName = "AntDeviceState", Level = LogLevel.Debug, Message = "{MethodName} {AntDevice} Device# {DeviceNumber}, Offline = {Offline}, Timeout = {Timeout}ms")] private static partial void s_logAntDeviceState(ILogger logger, string methodName, AntDevice antDevice, uint deviceNumber, bool offline, int timeout); /// @@ -117,7 +117,7 @@ public static void LogAntCollectionChange(this ILogger logger, AntDevice antDevi s_logAntCollectionChange(logger, methodName, antDevice, antDevice.ChannelId.DeviceNumber); } - [LoggerMessage(EventId = 1006, Level = LogLevel.Debug, Message = "{MethodName}: {AntDevice} Device# {DeviceNumber}")] + [LoggerMessage(EventId = 1006, EventName = "AntCollectionChange", Level = LogLevel.Debug, Message = "{MethodName}: {AntDevice} Device# {DeviceNumber}")] private static partial void s_logAntCollectionChange(ILogger logger, string methodName, AntDevice antDevice, uint deviceNumber); /// @@ -132,7 +132,7 @@ public static void LogUnhandledAntResponse(this ILogger logger, AntResponse antR s_logUnhandledAntResponse(logger, methodName, antResponse.ChannelNumber, antResponse.ResponseId, payload); } - [LoggerMessage(EventId = 1011, Level = LogLevel.Warning, Message = "{MethodName}: Unhandled ANT response. Channel# {Channel}, Response ID = {ResponseId}, Payload = {Payload}")] + [LoggerMessage(EventId = 1011, EventName = "UnhandledAntResponse", Level = LogLevel.Warning, Message = "{MethodName}: Unhandled ANT response. Channel# {Channel}, Response ID = {ResponseId}, Payload = {Payload}")] private static partial void s_logUnhandledAntResponse(ILogger logger, string methodName, byte channel, MessageId responseId, string payload); /// @@ -147,7 +147,7 @@ public static void LogIgnoredDataPage(this ILogger logger, byte[] dataPag s_logIgnoredPage(logger, methodName, Enum.GetName(typeof(TEnum), dataPage[0]), BitConverter.ToString(dataPage)); } - [LoggerMessage(EventId = 1008, Level = LogLevel.Warning, Message = "{MethodName}: Ignoring page type {Page}, Data page = {DataPage}. The page was unexpected or not implemented.")] + [LoggerMessage(EventId = 1008, EventName = "IgnoredDataPage", Level = LogLevel.Warning, Message = "{MethodName}: Ignoring page type {Page}, Data page = {DataPage}. The page was unexpected or not implemented.")] private static partial void s_logIgnoredPage(ILogger logger, string methodName, string? page, string dataPage); /// @@ -162,7 +162,7 @@ public static void LogDataPage(this ILogger logger, LogLevel level, byte[] dataP s_logDataPage(logger, level, deviceNumber, BitConverter.ToString(dataPage)); } - [LoggerMessage(EventId = 1009, Message = "DeviceNumber={DeviceNumber}: Data page = {DataPage}")] + [LoggerMessage(EventId = 1009, EventName = "DataPage", Message = "DeviceNumber={DeviceNumber}: Data page = {DataPage}")] private static partial void s_logDataPage(ILogger logger, LogLevel level, uint deviceNumber, string dataPage); /// @@ -179,7 +179,7 @@ public static void LogDataPage(this ILogger logger, LogLevel level, int p s_logDataPage(logger, level, methodName, Enum.ToObject(typeof(TEnum), dataPage[pageIndex])?.ToString(), BitConverter.ToString(dataPage)); } - [LoggerMessage(EventId = 1010, Message = "{MethodName}: Enum value = {EnumValue}, Data page = {DataPage}")] + [LoggerMessage(EventId = 1010, EventName = "DataPageEnum", Message = "{MethodName}: Enum value = {EnumValue}, Data page = {DataPage}")] private static partial void s_logDataPage(ILogger logger, LogLevel level, string methodName, string? enumValue, string dataPage); } } diff --git a/Examples/AntUsbStick/AntChannel.cs b/Examples/AntUsbStick/AntChannel.cs index 4f54adc9..8a7d4bb4 100644 --- a/Examples/AntUsbStick/AntChannel.cs +++ b/Examples/AntUsbStick/AntChannel.cs @@ -23,12 +23,12 @@ internal AntChannel(ANT_Channel channel, ILogger logger) _antChannel = channel; channel.channelResponse += OnChannelResponse; channel.DeviceNotification += OnDeviceNotification; - _logger.LogDebug("Created AntChannel #{Channel}", ChannelNumber); + _logger.LogDebug(new EventId(1001, "ctor"), "Created AntChannel #{Channel}", ChannelNumber); } private void OnDeviceNotification(ANT_Device.DeviceNotificationCode notification, object notificationInfo) { - _logger.LogDebug("Notification: {Notification} Info: {NotificationInfo}", notification, notificationInfo); + _logger.LogDebug(new EventId(1002, "OnDeviceNotification"), "AntChannel #{Channel}: Notification={Notification}, Info={NotificationInfo}", ChannelNumber, notification, notificationInfo); } private void OnChannelResponse(ANT_Response response) @@ -258,7 +258,7 @@ public void Dispose() { if (_antChannel != null) { - _logger.LogDebug("Disposed AntChannel #{Channel}", ChannelNumber); + _logger.LogDebug(new EventId(1003, "Dispose"), "Disposed AntChannel #{Channel}", ChannelNumber); _antChannel.channelResponse -= OnChannelResponse; _antChannel.DeviceNotification -= OnDeviceNotification; _antChannel.Dispose(); diff --git a/Examples/AntUsbStick/AntRadio.cs b/Examples/AntUsbStick/AntRadio.cs index 32f131ce..af0fadaf 100644 --- a/Examples/AntUsbStick/AntRadio.cs +++ b/Examples/AntUsbStick/AntRadio.cs @@ -42,12 +42,12 @@ public AntRadio(ILogger logger) _antDevice = new ANT_Device(); _antDevice.deviceResponse += OnDeviceResponse; _antDevice.serialError += OnAntDeviceSerialError; - _logger.LogDebug("Created AntRadio #{DeviceNum}", _antDevice.getOpenedUSBDeviceNum()); + _logger.LogDebug(new EventId(1004, ".ctor"), "Created AntRadio #{SerialNumber}", SerialNumber); } private void OnAntDeviceSerialError(ANT_Device sender, ANT_Device.serialErrorCode error, bool isCritical) { - _logger.LogError("OnAntDeviceSerialError: Sender: {Sender} Error: {Error} Critical: {IsCritical}", sender, error, isCritical); + _logger.LogError(new EventId(1005, "OnAntDeviceSerialError"), "AntRadio #{SerialNumber}: Error={Error}, Critical={IsCritical}", SerialNumber, error, isCritical); // if the error is critical, close the device and reinitialize if (isCritical) @@ -57,13 +57,13 @@ private void OnAntDeviceSerialError(ANT_Device sender, ANT_Device.serialErrorCod _antDevice = new ANT_Device(); _antDevice.deviceResponse += OnDeviceResponse; _antDevice.serialError += OnAntDeviceSerialError; - _logger.LogWarning("Reinitialized AntRadio #{DeviceNum}", _antDevice.getOpenedUSBDeviceNum()); + _logger.LogWarning(new EventId(1006, "OnAntDeviceSerialError"), "Reinitialized AntRadio #{SerialNumber}", SerialNumber); } } private void OnDeviceResponse(ANT_Response response) { - _logger.LogDebug("OnDeviceResponse: {Channel}, {ResponseId}, {Data}", response.antChannel, (MessageId)response.responseID, BitConverter.ToString(response.messageContents)); + _logger.LogDebug(new EventId(1007, "OnDeviceResponse"), "AntRadio #{SerialNumber}: Channel={Channel}, ResponseId={ResponseId}, Data={Data}", SerialNumber, response.antChannel, (MessageId)response.responseID, BitConverter.ToString(response.messageContents)); RadioResponse?.Invoke(this, new UsbAntResponse(response)); } @@ -84,7 +84,7 @@ public Task InitializeContinuousScanMode() if (_channels == null) { // allocate channels for this radio - _logger.LogInformation("Allocating channels for continuous scan mode."); + _logger.LogInformation(new EventId(1008, "InitializeContinuousScanMode"), "AntRadio #{SerialNumber}: Configuring channels for continuous scan mode.", SerialNumber); _channels = new IAntChannel[NumChannels]; // configure channel 0 for continuous scan mode @@ -118,7 +118,7 @@ public void Dispose() { if (_antDevice != null) { - _logger.LogDebug("Disposed AntRadio #{DeviceNum}", _antDevice.getOpenedUSBDeviceNum()); + _logger.LogDebug(new EventId(1009, "Dispose"), "Disposed AntRadio #{SerialNumber}", SerialNumber); _antDevice.deviceResponse -= OnDeviceResponse; _antDevice.serialError -= OnAntDeviceSerialError; _antDevice.Dispose(); diff --git a/Examples/AntUsbStick/AntUsbStick.csproj b/Examples/AntUsbStick/AntUsbStick.csproj index 09caee7b..591bdafd 100644 --- a/Examples/AntUsbStick/AntUsbStick.csproj +++ b/Examples/AntUsbStick/AntUsbStick.csproj @@ -6,7 +6,7 @@ True SmallEarthTech.$(MSBuildProjectName) Garmin/Dynastream ANT+ USB Stick Class Library - 4.1.4 + 4.1.5 True Stephen Hidem Provides an interface to ANT+ USB sticks available from Garmin/Dynastream. This class is used in the example projects located at the project URL. @@ -22,7 +22,7 @@ $(AssemblyName) PackageLogo.png - 1. Updated NuGet dependencies. + 1. Improved logging messages for better debugging and monitoring of ANT+ device interactions. Debug;Release OSMFEULA.txt diff --git a/Examples/MAUI-gRPC/MauiAntGrpcClient/MauiAntGrpcClient.csproj b/Examples/MAUI-gRPC/MauiAntGrpcClient/MauiAntGrpcClient.csproj index b845f123..90c27814 100644 --- a/Examples/MAUI-gRPC/MauiAntGrpcClient/MauiAntGrpcClient.csproj +++ b/Examples/MAUI-gRPC/MauiAntGrpcClient/MauiAntGrpcClient.csproj @@ -94,10 +94,10 @@ - - + + - + diff --git a/Extensions/Hosting/Hosting.UnitTests/Hosting.UnitTests.csproj b/Extensions/Hosting/Hosting.UnitTests/Hosting.UnitTests.csproj index 14c55157..531dfcca 100644 --- a/Extensions/Hosting/Hosting.UnitTests/Hosting.UnitTests.csproj +++ b/Extensions/Hosting/Hosting.UnitTests/Hosting.UnitTests.csproj @@ -15,7 +15,7 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - + all