如何实现以下方法?
string BuildSerilogMessage(string messageTemplate, params object[] propertyValues);
ILogger.Debug
论点与等接受的论点相同。
我想要这个的原因是因为我想在一个中间异常中保留模板/值,它也需要有单个字符串消息。基本上是这样的:
// this exception is designed to be easily loggable by serilog
[Serializable]
public class StructuredException : Exception {
public string MessageTemplate { get; private set; }
public object[] PropertyValues { get; private set; }
public StructuredException(string messageTemplate, params object[] propertyValues)
: base(BuildMessage(messageTemplate, propertyValues))
{
MessageTemplate = messageTemplate;
PropertyValues = propertyValues;
}
public StructuredException(Exception inner, string messageTemplate, params object[] propertyValues)
: base(BuildMessage(messageTemplate, propertyValues), inner)
{
MessageTemplate = messageTemplate;
PropertyValues = propertyValues;
}
private static string BuildMessage(string messageTemplate, object[] propertyValues) {
// ???
}
}