Class MessageService
Class for the loggers and other messaging functions.
public class MessageService
- Inheritance
-
MessageService
- Inherited Members
- Extension Methods
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.
public MessageCollection CurrentMessages { get; }
Property Value
ExceptionTranslator
Gets the exception translator.
public ExceptionTranslator ExceptionTranslator { get; }
Property Value
Instance
Gets the instance of MessageService.
public static MessageService Instance { get; }
Property Value
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.
public ILoggerFactory LoggerFactory { get; }
Property Value
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.
public IEnumerable<ILisrtModule> RootModules { get; set; }
Property Value
Methods
Acknowledge()
Clears all acknowledgeable messages from CurrentMessages .
public void Acknowledge()
AddStateMessage(IStateMessage)
Add a IStateMessage to the CurrentMessages".
public void AddStateMessage(IStateMessage message)
Parameters
message
IStateMessageThe IMessage item to add.
Exceptions
- ArgumentNullException
Thrown when message has value null.
LogCommunication(string, TransmissionDirection, byte[], string, ILogger)
Rise the CommunicationLogged and logs with ILogger.
public void LogCommunication(string moduleName, TransmissionDirection direction, byte[] data, string comment = "", ILogger logger = null)
Parameters
moduleName
stringThe communicating ILisrtModules full name.
direction
TransmissionDirectionThe communication direction.
data
byte[]The sent data.
comment
stringComment for the data.
logger
ILoggerLogger instance, if null then set in MessageService.
LogCommunication(string, TransmissionDirection, string, string, ILogger)
Rise the CommunicationLogged and logs with ILogger.
public void LogCommunication(string moduleName, TransmissionDirection direction, string data, string comment = "", ILogger logger = null)
Parameters
moduleName
stringThe communicating ILisrtModules full name.
direction
TransmissionDirectionThe communication direction.
data
stringThe sent data.
comment
stringComment for the data.
logger
ILoggerLogger instance. When it is null, the MessageService logger is used.
RemoveStateMessage(IStateMessage)
Remove a existing IStateMessage from CurrentMessages.
public bool RemoveStateMessage(IStateMessage message)
Parameters
message
IStateMessageIStateMessage which exists in CurrentMessages.
Returns
- bool
True if the element is successfully found and removed; otherwise, false.
Exceptions
- ArgumentNullException
Thrown when message has value null.
ShowException(Exception, ILogger)
Shows and logs an Exception.
public void ShowException(Exception ex, ILogger logger)
Parameters
ex
ExceptionException to show, if null then set in MessageService.
logger
ILoggerLogger instance, if null then set in MessageService.
ShowMessage(IMessage, ILogger)
Log a IMessage and add it to the CurrentMessages.
public void ShowMessage(IMessage message, ILogger logger)
Parameters
message
IMessageMessage with IMessage, if null then set to MessageBase.
logger
ILoggerLogger instance with ILogger, if null then set in MessageService.
Events
Acknowledged
Occurs after acknowledgment.
public event EventHandler Acknowledged
Event Type
CommunicationLogged
Occurs when a communication transmission was logged.
public event EventHandler<CommunicationLoggedEventArgs> CommunicationLogged