Class DiagnosticMessage
Defines an abstract base class for diagnostic messages. Diagnostic messages make it possible not to write long messages inside the actual code but centralize them in better manageable separate contexts.
Inheritance
Inherited Members
Namespace: Juhta.Net.Diagnostics
Assembly: Juhta.Net.dll
Syntax
public abstract class DiagnosticMessage
Constructors
| Improve this Doc View SourceDiagnosticMessage(DiagnosticMessageType, String)
Initializes a new instance.
Declaration
protected DiagnosticMessage(DiagnosticMessageType type, string message)
Parameters
Type | Name | Description |
---|---|---|
DiagnosticMessageType | type | Specifies a value for the Type property. |
System.String | message | Specifies a message that will be associated with the instance. The value can contain format items. |
DiagnosticMessage(DiagnosticMessageType, String, String)
Initializes a new instance.
Declaration
protected DiagnosticMessage(DiagnosticMessageType type, string message, string id)
Parameters
Type | Name | Description |
---|---|---|
DiagnosticMessageType | type | Specifies a value for the Type property. |
System.String | message | Specifies a message that will be associated with the instance. The value can contain format items. |
System.String | id | Specifies a value for the Id property. |
Properties
| Improve this Doc View SourceId
Gets the identifier of the diagnostic message that this DiagnosticMessage instance represents.
Declaration
public string Id { get; }
Property Value
Type | Description |
---|---|
System.String |
Message
Gets the message associated with this DiagnosticMessage instance.
Declaration
public string Message { get; }
Property Value
Type | Description |
---|---|
System.String |
Remarks
The value can contain format items.
Type
Gets the type of the diagnostic message that this DiagnosticMessage instance represents.
Declaration
public DiagnosticMessageType Type { get; }
Property Value
Type | Description |
---|---|
DiagnosticMessageType |
Methods
| Improve this Doc View SourceFormatMessage(Object[])
Formats the message stored in this DiagnosticMessage instance with specified objects.
Declaration
public string FormatMessage(params object[] args)
Parameters
Type | Name | Description |
---|---|---|
System.Object[] | args | Specifies an array of objects to format. Can be null. |
Returns
Type | Description |
---|---|
System.String | Returns the formatted message. If the specified object array doesn't match the format items in the message stored in this DiagnosticMessage instance, the method just returns the message without any formatting. |
GetIntegerId()
Gets an integer identifier out of the Id property of this DiagnosticMessage instance.
Declaration
public int GetIntegerId()
Returns
Type | Description |
---|---|
System.Int32 | Returns the greatest whole number fragment in the Id property of this DiagnosticMessage instance as an integer. If there are no whole number fragments in the Id property, the return value is zero. |
See Also
| Improve this Doc View SourceGetIntegerId(String)
Gets an integer identifier out of a specified string identifier.
Declaration
public static int GetIntegerId(string id)
Parameters
Type | Name | Description |
---|---|---|
System.String | id | Specifies a string identifier. |
Returns
Type | Description |
---|---|
System.Int32 | Returns the greatest whole number fragment in the specified string identifier as an integer. If there are no whole number fragments in the string identifier, the return value is zero. |
See Also
| Improve this Doc View SourceGetMessage()
Gets the message stored in this DiagnosticMessage instance without any formatting.
Declaration
public string GetMessage()
Returns
Type | Description |
---|---|
System.String | Returns the stored message without any formatting. |
Remarks
Use this method instead of FormatMessage(Object[]) when the message contains no format items.
TryGetMessageId(Exception, out String)
Tries to get an identifier for the message of a specified exception.
Declaration
public static bool TryGetMessageId(Exception exception, out string messageId)
Parameters
Type | Name | Description |
---|---|---|
System.Exception | exception | Specifies an exception. |
System.String | messageId | If the function returns true, returns the identifier of the message of the specified exception, otherwise returns null. |
Returns
Type | Description |
---|---|
System.Boolean | Returns true if an identifier was found for the message of the specified exception, otherwise returns false. |
Remarks
If the specified exception contains inner exceptions, the innermost exception with a found identifier match is decisive (root cause exception).
Searching will be done in the last formatted messages for the current thread.
TryGetMessageId(String, out String)
Tries to get an identifier for a specified message.
Declaration
public static bool TryGetMessageId(string message, out string messageId)
Parameters
Type | Name | Description |
---|---|---|
System.String | message | Specifies a message. |
System.String | messageId | If the function returns true, returns the identifier of the specified message, otherwise returns null. |
Returns
Type | Description |
---|---|
System.Boolean | Returns true if an identifier was found for the specified message, otherwise returns false. |
Remarks
Searching will be done in the last formatted messages for the current thread.