C# 企业库日志记录和文本格式化程序模板标记。如何?
我正在尝试让我的日志组件按我所希望的方式工作。当我看到这个帖子的时候 我发现格式化程序:C# 企业库日志记录和文本格式化程序模板标记。如何?,c#,enterprise-library-6,C#,Enterprise Library 6,我正在尝试让我的日志组件按我所希望的方式工作。当我看到这个帖子的时候 我发现格式化程序: 包含我不知道如何使用的“文本格式化程序模板标记” "Stack trace: {property(StackTrace)}{newline}
" 目前我的日志类如下所示: public class Logging : Microsoft.Practices.EnterpriseLibrary.Logging.LogEntry { /// <summary&
包含我不知道如何使用的“文本格式化程序模板标记”
"Stack trace: {property(StackTrace)}{newline}
"
目前我的日志类如下所示:
public class Logging : Microsoft.Practices.EnterpriseLibrary.Logging.LogEntry
{
/// <summary>
/// Logs an error message.
/// </summary>
/// <param name="Message"></param>
/// <param name="processEvent"></param>
public void LogToFile(string message, System.Diagnostics.TraceEventType severity)
{
try
{
LogWriterFactory logWriterFactory = new LogWriterFactory();
LogWriter logWriter = logWriterFactory.Create();
LogEntry logEntry = new LogEntry();
LogSource logsource = new LogSource("ESRAlarmStatistik");
logEntry.Message = message.ToString();
//logEntry.EventId = Convert.ToInt32(processEvent);
logEntry.Priority = 2;
logEntry.Severity = severity;
logEntry.TimeStamp = System.DateTime.Now;
logWriter.Write(logEntry);
//Unlocks the logfile so that it's possible to delete it.
logWriter.Dispose();
}
catch (LoggingException ex)
{
throw ex;
}
}
}
公共类日志记录:Microsoft.Practices.EnterpriseLibrary.Logging.LogEntry
{
///
///记录一条错误消息。
///
///
///
公共无效日志文件(字符串消息,System.Diagnostics.TraceEventType严重性)
{
尝试
{
LogWriterFactory LogWriterFactory=新LogWriterFactory();
LogWriter LogWriter=logWriterFactory.Create();
LogEntry LogEntry=新的LogEntry();
LogSource LogSource=新的LogSource(“ESRarmStatistik”);
logEntry.Message=Message.ToString();
//logEntry.EventId=Convert.ToInt32(processEvent);
logEntry.Priority=2;
日志条目。严重性=严重性;
logEntry.TimeStamp=System.DateTime.Now;
logWriter.Write(logEntry);
//解锁日志文件,以便可以删除它。
logWriter.Dispose();
}
捕获(LoggingException ex)
{
掷骰子;
}
}
}
我想记录更多关于异常的信息,而不仅仅是消息。例如,文本格式化程序模板标记建议的堆栈跟踪是可能的
但是,我不知道怎么做?有没有人有过如何实现对上述文本格式化程序的支持的经验
此时的日志输出如下所示:
----------------------------------------
Application: <Error: property ApplicationName not found>
Guid: <Error: property HandlingInstanceId not found>
Timestamp: 2016-04-03 10:16:20
Message: IngresDatabaseAccessor.DBConnect() - Database connection failed. Connection string: Host=192.168.0.114;User Id=ingres;PWD=ingres;Database=esra_bas---Database does not exist: 'esrk_bas'.
The connection to the server has been aborted.
Exception type: <Error: property ExceptionType not found>
Category: General
Severity: Error
Machine: KSD53
App Domain: ESRAlarmStatistik.exe
ProcessId: 15464
Process Name: C:\DATA\Development\Uddeholm\ESR\Source\Common\ESRAlarmStatistik\ESRAlarmStatistik\bin\Debug\ESRAlarmStatistik.exe
Stack trace: <Error: property StackTrace not found>
File: <Error: property FileName not found>
Line: <Error: property LineNumber not found>
----------------------------------------
----------------------------------------
应用程序:
Guid:
时间戳:2016-04-03 10:16:20
消息:IngreDatabaseAccessor.DBConnect()-数据库连接失败。连接字符串:主机=192.168.0.114;用户Id=安格尔;PWD=安格尔;数据库=esra\U bas---数据库不存在:“esrk\U bas”。
与服务器的连接已中止。
异常类型:
类别:一般
严重性:错误
机器:KSD53
应用程序域:esrarmstatistik.exe
进程ID:15464
进程名称:C:\DATA\Development\Uddeholm\ESR\Source\Common\esrarmstatistik\esrarmstatistik\bin\Debug\esrarmstatistik.exe
堆栈跟踪:
文件:
行:
----------------------------------------
亲切的问候
另外,我正在使用Enterprise Library 6.0,它看起来像您的
LogEntry logEntry = new LogEntry();
不包含格式化程序请求的属性:
logEntry.StackTrace = "missing Informaton in your LogToFile Method"
所以我认为,你必须扩展这个