Log4Net:将 C# AdoNetAppender 与自定义 Xml 布局结合使用
我有点卡住了。我一直在编写一个日志记录模块,它要求附加程序能够在数据库上执行存储过程来记录我们的信息。我编写了一个自定义 xml 布局,如下所示:
protected override void FormatXml(XmlWriter writer, LoggingEvent loggingEvent)
{
writer.WriteStartElement("LogEntry");
writer.WriteStartElement("DateTime");
writer.WriteString(loggingEvent.TimeStamp.ToLongTimeString());
writer.WriteEndElement();
writer.WriteStartElement("Message");
writer.WriteString(loggingEvent.RenderedMessage);
writer.WriteEndElement();
writer.WriteStartElement("User");
writer.WriteString(loggingEvent.UserName);
writer.WriteEndElement();
writer.WriteStartElement("Process");
writer.WriteString(loggingEvent.ThreadName);
writer.WriteEndElement();
writer.WriteStartElement("Severity");
writer.WriteString(loggingEvent.Level.ToString());
writer.WriteEndElement();
writer.WriteStartElement("Title");
writer.WriteString(loggingEvent.LoggerName);
writer.WriteEndElement();
writer.WriteStartElement("Class");
writer.WriteString(loggingEvent.LocationInformation.ClassName);
writer.WriteEndElement();
writer.WriteStartElement("Filename");
writer.WriteString(loggingEvent.LocationInformation.FileName);
writer.WriteEndElement();
writer.WriteEndElement();
}
所以基本上,我希望 AdoNetAppender 通过此布局运行日志记录事件,然后使用生成的 Xml 作为参数执行 storproc。即
EXEC Logging.InsertEntry @XML
不幸的是,周围似乎没有任何例子。
任何帮助将不胜感激。
I'm a bit stuck. I've been writing a logging module which requires the appender being able to execute a stored procedure on the database to log our information. I have written a custom xml layout which is as follows:
protected override void FormatXml(XmlWriter writer, LoggingEvent loggingEvent)
{
writer.WriteStartElement("LogEntry");
writer.WriteStartElement("DateTime");
writer.WriteString(loggingEvent.TimeStamp.ToLongTimeString());
writer.WriteEndElement();
writer.WriteStartElement("Message");
writer.WriteString(loggingEvent.RenderedMessage);
writer.WriteEndElement();
writer.WriteStartElement("User");
writer.WriteString(loggingEvent.UserName);
writer.WriteEndElement();
writer.WriteStartElement("Process");
writer.WriteString(loggingEvent.ThreadName);
writer.WriteEndElement();
writer.WriteStartElement("Severity");
writer.WriteString(loggingEvent.Level.ToString());
writer.WriteEndElement();
writer.WriteStartElement("Title");
writer.WriteString(loggingEvent.LoggerName);
writer.WriteEndElement();
writer.WriteStartElement("Class");
writer.WriteString(loggingEvent.LocationInformation.ClassName);
writer.WriteEndElement();
writer.WriteStartElement("Filename");
writer.WriteString(loggingEvent.LocationInformation.FileName);
writer.WriteEndElement();
writer.WriteEndElement();
}
So basically, i'd like the AdoNetAppender to run the logging event through this layout and then execute the storproc with the resulting Xml as the parameter. i.e.
EXEC Logging.InsertEntry @XML
Unfortunately there doesn't seem to be any examples around.
Any help would be extremely appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
像这样的东西应该可以工作(SQL Server):
但是我确实想知道您是否不想创建一个存储过程,该存储过程为您的 xml 结构中的所有元素提供一个参数...
Something like this should work (SQL Server):
I do wonder however if you would not rather create a stored procedure that has a parameter for all the elements in your xml structure...