2016-04-03 2 views
3

Ich versuche, meine Logging-Komponente zu arbeiten, wie ich will. Als ich auf diesen Beitrag kam How to configure Enterpise Library 6.0 logging to database?Enterprise-Bibliotheksprotokollierung und Textformatter-Vorlagen-Token. Wie man?

ich, dass die Formatter entdeckt:

<formatters> 
    <add type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" template="Application: {property(ApplicationName)}{newline}&#xA;Guid: {property(HandlingInstanceId)}{newline}&#xA;Timestamp: {timestamp}{newline}&#xA;Message: {message}{newline}&#xA;Exception type: {property(ExceptionType)}{newline}&#xA;Category: {category}{newline}&#xA;Severity: {severity}{newline}&#xA;Machine: {localMachine}{newline}&#xA;App Domain: {localAppDomain}{newline}&#xA;ProcessId: {localProcessId}{newline}&#xA;Process Name: {localProcessName}{newline}&#xA;Stack trace: {property(StackTrace)}{newline}&#xA;File: {property(FileName)}{newline}&#xA;Line: {property(LineNumber)}{newline}" 
    name="Text Formatter" /> 
</formatters> 

enthält „Text Formatter Vorlage Tokens“, die ich weiß nicht, wie zu benutzen?

"Stack trace: {property(StackTrace)}{newline}&#xA" 

Meine Logging-Klasse im Moment wie folgt aussieht:

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; 
     } 
    } 
} 

Ich möchte mehr Informationen über die Ausnahme loggt sein als nur die Nachricht. Z.B. Der Stack-Trace, wie das Textformatter-Template-Token vermuten lässt, ist möglich.

Allerdings weiß ich nicht, wie das geht? Hat jemand Erfahrung mit der Implementierung von Unterstützung für einen Textformatierer wie den obigen?

Die Log-Ausgabe sieht wie folgt aus im Moment:

---------------------------------------- 
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> 

---------------------------------------- 

Mit freundlichen Grüßen!

Ps.s. Ich verwende Enterprise Library 6.0

Antwort

0

es sieht aus, wie Ihr

LogEntry logEntry = new LogEntry(); 

nicht enthält Eigenschaften, die von der Formatierung angefordert:

logEntry.StackTrace = "missing Informaton in your LogToFile Method" 

Ich denke also, müssen Sie diese erweitern.