Class MessageService
Class for the loggers and other messaging functions.
Inherited Members
Namespace: Loehnert.Lisrt.Messaging
Assembly: Loehnert.Lisrt.dll
Syntax
public class MessageService
Remarks
This class has a Singleton-Pattern and is initialized with the first access. For using you have to use MessageService.Instance. ...
Properties
CurrentMessages
Gets a collection of IMessage items which were set or not acknowledged.
Declaration
public MessageCollection CurrentMessages { get; }
Property Value
Type | Description |
---|---|
MessageCollection |
ExceptionTranslator
Gets the exception translator.
Declaration
public ExceptionTranslator ExceptionTranslator { get; }
Property Value
Type | Description |
---|---|
ExceptionTranslator |
Instance
Gets the instance of MessageService.
Declaration
public static MessageService Instance { get; }
Property Value
Type | Description |
---|---|
MessageService |
Remarks
Initialize the LoggerFactory and complete the dictionary for the ExceptionTranslator. Adds event handler for AppDomain.CurrentDomain.FirstChanceException to do ShowException(Exception, ILogger).
LoggerFactory
Gets the logger factory.
Declaration
public ILoggerFactory LoggerFactory { get; }
Property Value
Type | Description |
---|---|
ILoggerFactory |
Remarks
Factory for producing a Logger. LoggerFactory must be set in the App.config, otherwise NLogLoggerFactory will be used.
RootModules
Gets or sets the root modules. Set this property to show module name in messages.
Declaration
public IEnumerable<ILisrtModule> RootModules { get; set; }
Property Value
Type | Description |
---|---|
IEnumerable<ILisrtModule> |
Methods
Acknowledge()
Clears all acknowledgeable messages from CurrentMessages .
Declaration
public void Acknowledge()
AddStateMessage(IStateMessage)
Add a IStateMessage to the CurrentMessages".
Declaration
public void AddStateMessage(IStateMessage message)
Parameters
Type | Name | Description |
---|---|---|
IStateMessage | message | The IMessage item to add. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | Thrown when message has value null. |
LogCommunication(String, TransmissionDirection, Byte[], String, ILogger)
Rise the CommunicationLogged and logs with ILogger.
Declaration
public void LogCommunication(string moduleName, TransmissionDirection direction, byte[] data, string comment = "", ILogger logger = null)
Parameters
Type | Name | Description |
---|---|---|
String | moduleName | The communicating ILisrtModules full name. |
TransmissionDirection | direction | The communication direction. |
System.Byte[] | data | The sent data. |
String | comment | Comment for the data. |
ILogger | logger | Logger instance, if null then set in MessageService. |
LogCommunication(String, TransmissionDirection, String, String, ILogger)
Rise the CommunicationLogged and logs with ILogger.
Declaration
public void LogCommunication(string moduleName, TransmissionDirection direction, string data, string comment = "", ILogger logger = null)
Parameters
Type | Name | Description |
---|---|---|
String | moduleName | The communicating ILisrtModules full name. |
TransmissionDirection | direction | The communication direction. |
String | data | The sent data. |
String | comment | Comment for the data. |
ILogger | logger | Logger instance. When it is null, the MessageService logger is used. |
RemoveStateMessage(IStateMessage)
Remove a existing IStateMessage from CurrentMessages.
Declaration
public bool RemoveStateMessage(IStateMessage message)
Parameters
Type | Name | Description |
---|---|---|
IStateMessage | message | IStateMessage which exists in CurrentMessages. |
Returns
Type | Description |
---|---|
Boolean | True if the element is successfully found and removed; otherwise, false. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | Thrown when message has value null. |
ShowException(Exception, ILogger)
Shows and logs an System.Exception.
Declaration
public void ShowException(Exception ex, ILogger logger)
Parameters
Type | Name | Description |
---|---|---|
System.Exception | ex | Exception to show, if null then set in MessageService. |
ILogger | logger | Logger instance, if null then set in MessageService. |
ShowMessage(IMessage, ILogger)
Log a IMessage and add it to the CurrentMessages.
Declaration
public void ShowMessage(IMessage message, ILogger logger)
Parameters
Type | Name | Description |
---|---|---|
IMessage | message | Message with IMessage, if null then set to MessageBase. |
ILogger | logger | Logger instance with ILogger, if null then set in MessageService. |
Events
Acknowledged
Occurs after acknowledgment.
Declaration
public event EventHandler Acknowledged
Event Type
Type | Description |
---|---|
System.EventHandler |
CommunicationLogged
Occurs when a communication transmission was logged.
Declaration
public event EventHandler<CommunicationLoggedEventArgs> CommunicationLogged
Event Type
Type | Description |
---|---|
System.EventHandler<CommunicationLoggedEventArgs> |
Remarks
Fired in LogCommunication(String, TransmissionDirection, Byte[], String, ILogger) and LogCommunication(String, TransmissionDirection, String, String, ILogger).