当这样的消息进来时,我想初始化一些日志记录:
public class BaseMessage
{
public long TraceID { get; set; }
}
public class MyMessage : BaseMessage, ICommand
{
//..other properties
}
public class Handler : IHandleMessages<MyMessage>
{
public void Handle(MyMessage message)
{
log4net.ThreadContext.Properties["TraceID"] = message.TraceID
//Process message
}
}
问题是我有很多消息,我想在收到消息时为所有消息都这样做。我希望能够做这样的事情:
public class Handler : IInitializeHandlers, IHandleMessages<MyMessage>
{
public void Init(BaseMessage message)
{
log4net.ThreadContext.Properties["TraceID"] = ((BaseMessage)message).TraceID
}
public void Handle(MyMessage message)
{
//Process message
}
}