diff --git a/LogicMonitor.Api.Test/Logging/LoggingTests.cs b/LogicMonitor.Api.Test/Logging/LoggingTests.cs
index bab6b8b7..6c642046 100644
--- a/LogicMonitor.Api.Test/Logging/LoggingTests.cs
+++ b/LogicMonitor.Api.Test/Logging/LoggingTests.cs
@@ -8,7 +8,7 @@ public class LoggingTests(ITestOutputHelper iTestOutputHelper) : TestWithOutput(
public async Task WriteLogAsync_WithResourceId_Succeeds()
{
var response = await LogicMonitorClient
- .WriteLogAsync(WriteLogLevel.Info, WindowsDeviceId, "Test log message.", default)
+ .WriteLogAsync(WriteLogLevel.Info, WindowsDeviceId, "Test log message against resource id.", default)
.ConfigureAwait(true);
response.Should().NotBeNull();
}
@@ -22,7 +22,7 @@ public async Task WriteLogAsync_WithResourceDisplayName_Succeeds()
.ConfigureAwait(true);
var response = await LogicMonitorClient
- .WriteLogAsync(WriteLogLevel.Info, windowsDevice.DisplayName, "Test log message.", default)
+ .WriteLogAsync(WriteLogLevel.Info, windowsDevice.DisplayName, "Test log message against resource display name.", default)
.ConfigureAwait(true);
response.Should().NotBeNull();
}
diff --git a/LogicMonitor.Api/Logging/WriteLogRequest.cs b/LogicMonitor.Api/Logging/WriteLogRequest.cs
index 38aa8950..9425591d 100644
--- a/LogicMonitor.Api/Logging/WriteLogRequest.cs
+++ b/LogicMonitor.Api/Logging/WriteLogRequest.cs
@@ -1,7 +1,7 @@
namespace LogicMonitor.Api.Logging;
///
-/// A request to write to a log against a resource id
+/// A request to write to a log against a resource
///
[DataContract]
public class WriteLogRequest : Dictionary
@@ -29,7 +29,7 @@ public WriteLogRequest(WriteLogLevel level, int resourceId, string message)
}
///
- /// Construct a regular deviceId WriteLogRequest
+ /// Construct a regular resourceDisplayName WriteLogRequest
///
///
///
@@ -43,6 +43,37 @@ public WriteLogRequest(WriteLogLevel level, string resourceDisplayName, string m
this["message"] = GetPrefix(level) + message;
}
+ ///
+ /// Construct a regular custom property WriteLogRequest
+ ///
+ ///
+ ///
+ ///
+ ///
+ public WriteLogRequest(WriteLogLevel level, string customPropertyName, string customPropertyValue, string message)
+ {
+ this["_lm.resourceId"] = new Dictionary
+ {
+ { customPropertyName, customPropertyValue }
+ };
+ this["message"] = GetPrefix(level) + message;
+ }
+
+ ///
+ /// Construct a regular custom property WriteLogRequest
+ ///
+ ///
+ ///
+ /// The property dictionary, the combination of which will be used to identify the resource.
+ /// This must be unique across the specified custom property values for the entire LM portal.
+ ///
+ ///
+ public WriteLogRequest(WriteLogLevel level, Dictionary propertyDictionary, string message)
+ {
+ this["_lm.resourceId"] = propertyDictionary;
+ this["message"] = GetPrefix(level) + message;
+ }
+
private static string GetPrefix(WriteLogLevel level) => level switch
{
WriteLogLevel.Trace => "[TRCE] ",
diff --git a/LogicMonitor.Api/LogicMonitorClient_Logging.cs b/LogicMonitor.Api/LogicMonitorClient_Logging.cs
index 3667df2d..eb7ffbb3 100644
--- a/LogicMonitor.Api/LogicMonitorClient_Logging.cs
+++ b/LogicMonitor.Api/LogicMonitorClient_Logging.cs
@@ -28,7 +28,7 @@ public Task WriteLogAsync(
=> WriteLogAsync(new[] { writeLogRequest }, cancellationToken);
///
- /// Logs a single writeLogRequest at the specified level
+ /// Logs a single writeLogRequest
///
///
/// The device id
@@ -43,10 +43,10 @@ public Task WriteLogAsync(
=> WriteLogAsync(new[] { new WriteLogRequest(writeLogLevel, deviceId, message) }, cancellationToken);
///
- /// Logs a single writeLogRequest at the informational level
+ /// Logs a single writeLogRequest
///
///
- /// The device id
+ /// The device display name
/// The message
///
/// The response
@@ -56,4 +56,42 @@ public Task WriteLogAsync(
string message,
CancellationToken cancellationToken)
=> WriteLogAsync(new[] { new WriteLogRequest(writeLogLevel, deviceDisplayName, message) }, cancellationToken);
+
+ ///
+ /// Logs a single writeLogRequest
+ ///
+ ///
+ /// The custom property name
+ ///
+ /// The custom property value.
+ /// This must be unique across for the specified custom property value for the entire LM portal.
+ ///
+ /// The message
+ ///
+ /// The response
+ public Task WriteLogAsync(
+ WriteLogLevel writeLogLevel,
+ string customPropertyName,
+ string customPropertyValue,
+ string message,
+ CancellationToken cancellationToken)
+ => WriteLogAsync(new[] { new WriteLogRequest(writeLogLevel, customPropertyName, customPropertyValue, message) }, cancellationToken);
+
+ ///
+ /// Logs a single writeLogRequest
+ ///
+ ///
+ ///
+ /// The property dictionary, the combination of which will be used to identify the resource.
+ /// This must be unique across the specified custom property values for the entire LM portal.
+ ///
+ /// The message
+ ///
+ /// The response
+ public Task WriteLogAsync(
+ WriteLogLevel writeLogLevel,
+ Dictionary propertyDictionary,
+ string message,
+ CancellationToken cancellationToken)
+ => WriteLogAsync(new[] { new WriteLogRequest(writeLogLevel, propertyDictionary, message) }, cancellationToken);
}