Microsoft.Practices.EnterpriseLibrary.Logging | Unable to write ERROR to a Log /text File

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
hello
I am using Enterprise library for logging and try to write the exception in a log file / text file.<br/>
What I did is I have copied required for Enterprise Library to my machine from a different machine (working project).
C# Code - <br/>
public static void LogError(Exception ex, string additionalMessage)<br/>
{<br/>
LogEntry logEntry = new LogEntry();
logEntry.Categories.Add("MedicalCongressErrors");<br/>
logEntry.Severity = TraceEventType.Error;<br/>
logEntry.Message = ex.Message;<br/>
if (!string.IsNullOrEmpty(ex.StackTrace))<br/>
{<br/>
logEntry.ExtendedProperties.Add("StackTrace:", ex.StackTrace);<br/>
}<br/>
logEntry.ExtendedProperties.Add("Additional Info:", additionalMessage);<br/>
logEntry.ExtendedProperties.Add("filelocation", @"C:LogsTest1.txt"); //newly Added .. can be COMMENTED as it there in web.config
<br/>
Logger.Write(logEntry);<br/>
}<br/>
Configured web.config -
<br/>
<section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<loggingConfiguration name="Logging Application Block" tracingEnabled="true" defaultCategory="General" logWarningsWhenNoCategoriesMatch="true <br/>
<listeners><br/>
<add fileName="C:LogsDashboardtrace.log" header="" footer="" formatter="DashboardTextFormatter" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging,
Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" traceOutputOptions="None" filter="All" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="FlatFile TraceListener"/><br/>
<add source="Enterprise Library Logging" formatter="Text Formatter" log="Application" machineName="" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging,
Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" traceOutputOptions="None" filter="All" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="Formatted EventLog TraceListener"/><br/>
</listeners><br/>
<formatters><br/>
<add template="Timestamp: {timestamp}&#xA;Message: {message}&#xA;EventId: {eventid}&#xA;Severity: {severity}&#xA;Machine: {machine}&#xA;Application Domain: {appDomain}&#xA;Extended Properties: {dictionary({key}
- {value}&#xA;)}" type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="DashboardTextFormatter"/><br/>
<add template="Timestamp: {timestamp}&#xA;Message: {message}&#xA;Category: {category}&#xA;Priority: {priority}&#xA;EventId: {eventid}&#xA;Severity: {severity}&#xA;Title:{title}&#xA;Machine: {machine}&#xA;Application
Domain: {appDomain}&#xA;Process Id: {processId}&#xA;Process Name: {processName}&#xA;Win32 Thread Id: {win32ThreadId}&#xA;Thread Name: {threadName}&#xA;Extended Properties: {dictionary({key} - {value}&#xA;)}" type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter,
Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="Text Formatter"/><br/>
</formatters><br/>
<logFilters><br/>
<add categoryFilterMode="DenyAllExceptAllowed" type="Microsoft.Practices.EnterpriseLibrary.Logging.Filters.CategoryFilter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
name="Category Filter <br/>
<categoryFilters><br/>
<add name="DashboardErrors"/><br/>
</categoryFilters><br/>
</add><br/>
</logFilters><br/>
<categorySources><br/>
<add switchValue="Error" name="DashboardErrors <br/>
<listeners><br/>
<add name="FlatFile TraceListener"/><br/>
</listeners><br/>
</add><br/>
<add switchValue="All" name="General <br/>
<listeners><br/>
<add name="Formatted EventLog TraceListener"/><br/>
</listeners><br/>
</add><br/>
</categorySources><br/>
<specialSources><br/>
<allEvents switchValue="All" name="All Events"/><br/>
<notProcessed switchValue="All" name="Unprocessed Category"/><br/>
<errors switchValue="All" name="Logging Errors &amp; Warnings <br/>
<listeners><br/>
<add name="Formatted EventLog TraceListener"/><br/>
</listeners><br/>
</errors><br/>
</specialSources><br/>
</loggingConfiguration>
Please HELP me in achieving this ... I dont think I am missing anything ...
Thanks<br/>
Santanu

View the full article
 
Back
Top