Logging application block not writing to the database

May 15, 2008 at 6:21 PM
Edited May 15, 2008 at 6:31 PM

I am adding the logging application to my vs2008 project and I am having issues using the database trace listners. Here is my configuration in web.config

<

configSections>  

 

 

<

section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />

 

 

<

section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />

 

 

 

 

<sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">

 

 

 <

sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">

 

 

<

section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>

 

<

sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">

 

<

section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="Everywhere"/>

 

<

section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>

 

 <

section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>

 

<

 

section name="roleService" type="System.Web.Configuration.ScriptingRoleServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>

</

sectionGroup>

 

 </

sectionGroup>

 

 </

sectionGroup>

 

 

</

configSections>

 

 <

loggingConfiguration name="Logging Application Block" tracingEnabled="true" defaultCategory="General" logWarningsWhenNoCategoriesMatch="true">

 

 <

listeners>

 

 <

add databaseInstanceName="PRTConnectString" writeLogStoredProcName="WriteLog" addCategoryStoredProcName="AddCategory" formatter="Text Formatter" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Database.Configuration.FormattedDatabaseTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging.Database, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" traceOutputOptions="None" type="Microsoft.Practices.EnterpriseLibrary.Logging.Database.FormattedDatabaseTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging.Database, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" name="Database Trace Listener" />

 

 <

add source="Enterprise Library Logging" formatter="Text Formatter" log="Application" machineName="" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" traceOutputOptions="DateTime" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" name="Formatted EventLog TraceListener" />

 

 </

listeners>

 

 <

formatters>

 

 <

add template="Timestamp: {timestamp}&#xD;&#xA;Message: {message}&#xD;&#xA;Category: {category}&#xD;&#xA;Priority: {priority}&#xD;&#xA;EventId: {eventid}&#xD;&#xA;Severity: {severity}&#xD;&#xA;Title:{title}&#xD;&#xA;Machine: {machine}&#xD;&#xA;Application Domain: {appDomain}&#xD;&#xA;Process Id: {processId}&#xD;&#xA;Process Name: {processName}&#xD;&#xA;Win32 Thread Id: {win32ThreadId}&#xD;&#xA;Thread Name: {threadName}&#xD;&#xA;Extended Properties: {dictionary({key} - {value}&#xD;&#xA;)}" type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" name="Text Formatter" />

 

 </

 

formatters>

 <

logFilters>

 

<

add categoryFilterMode="DenyAllExceptAllowed" type="Microsoft.Practices.EnterpriseLibrary.Logging.Filters.CategoryFilter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" name="Category Filter1">

 

 <

 

categoryFilters>

 <

add name="General" />

 

<

add name="Debug" />

 

 <

add name="UserAuthentication" />

 

 <

add name="UnlockAccount" />

 

<

add name="Password Reset" />

 

 </

categoryFilters>

 

 </

add>

 

 <

add enabled="true" type="Microsoft.Practices.EnterpriseLibrary.Logging.Filters.LogEnabledFilter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" name="LogEnabled Filter" />

 

</

logFilters>

 

 <

categorySources>

 

 <

add switchValue="All" name="Debug" />

 

 

<

add switchValue="All" name="General">

 

 

<l

isteners>

 

 

<

add name="Database Trace Listener" />

 

 </

listeners>

 

 

</

add>

 

 

<

add switchValue="All" name="Password Reset">

 

<

listeners>

 

 

<

add name="Database Trace Listener" />

 

 </

listeners>

 

 </

add>

 

 

<

add switchValue="All" name="UnlockAccount">

 

 <

listeners>

 

 <

add name="Database Trace Listener" />

 

 </

listeners>

 

 

</

add>

 

 

<

add switchValue="All" name="UserAuthentication">

 

 <

listeners>

 

 <

add name="Database Trace Listener" />

 

 

</

listeners>

 

 </

add>

 

 

</

categorySources>

 

 <

specialSources>

 

 <

allEvents switchValue="All" name="All Events">

 

 

<

listeners>

 

 

<

add name="Database Trace Listener" />

 

 

</

listeners>

 

 </

allEvents>

 

 

<

notProcessed switchValue="All" name="Unprocessed Category">

 

 

<l

isteners>

 

 

<

add name="Database Trace Listener" />

 

 

</

listeners>

 

 

</

notProcessed>

 

 

<

errors switchValue="All" name="Logging Errors &amp; Warnings">

 

 

<

listeners>

 

 

<

add name="Database Trace Listener" />

 

 

</

listeners>

 

 </

errors>

 

 

</

specialSources>

 

 </

loggingConfiguration>

 

 

 

 

Sample code to write a log to the database

 

LogEntry le = new LogEntry();

 

 

le.EventId = 1;

le.Message =

"test from user services";

 

 

 

string userName = User.Identity.Name;

 

le.ExtendedProperties.Add(

 

"UserName", userName);

 

le.Severity = System.Diagnostics.

 

TraceEventType.Information;

 

 

le.Title =

"UserLog";

 

 

 

Logger.Write(le);



I have the above code working on the another machine but when I publish the application and test the above code, nothing get written to the database.  Please help.

Thank you!


n


 

 

May 16, 2008 at 10:45 PM
Try configuring an event log trace listener for the "errors" special category and check the error log after a logging attempt for an entry describing the failure to log, if any.

Fernando


nettachfini wrote:

I am adding the logging application to my vs2008 project and I am having issues using the database trace listners. Here is my configuration in web.config

<

configSections>  

 

 

<

section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />

 

 

<

section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />

 

 

 

 

<sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">

 

 

 <

sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">

 

 

<

section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>

 

<

sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">

 

<

section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="Everywhere"/>

 

<

section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>

 

 <

section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>

 

<

 

section name="roleService" type="System.Web.Configuration.ScriptingRoleServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>

</

sectionGroup>

 

 </

sectionGroup>

 

 </

sectionGroup>

 

 

</

configSections>

 

 <

loggingConfiguration name="Logging Application Block" tracingEnabled="true" defaultCategory="General" logWarningsWhenNoCategoriesMatch="true">

 

 <

listeners>

 

 <

add databaseInstanceName="PRTConnectString" writeLogStoredProcName="WriteLog" addCategoryStoredProcName="AddCategory" formatter="Text Formatter" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Database.Configuration.FormattedDatabaseTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging.Database, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" traceOutputOptions="None" type="Microsoft.Practices.EnterpriseLibrary.Logging.Database.FormattedDatabaseTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging.Database, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" name="Database Trace Listener" />

 

 <

add source="Enterprise Library Logging" formatter="Text Formatter" log="Application" machineName="" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" traceOutputOptions="DateTime" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" name="Formatted EventLog TraceListener" />

 

 </

listeners>

 

 <

formatters>

 

 <

add template="Timestamp: {timestamp}&#xD;&#xA;Message: {message}&#xD;&#xA;Category: {category}&#xD;&#xA;Priority: {priority}&#xD;&#xA;EventId: {eventid}&#xD;&#xA;Severity: {severity}&#xD;&#xA;Title:{title}&#xD;&#xA;Machine: {machine}&#xD;&#xA;Application Domain: {appDomain}&#xD;&#xA;Process Id: {processId}&#xD;&#xA;Process Name: {processName}&#xD;&#xA;Win32 Thread Id: {win32ThreadId}&#xD;&#xA;Thread Name: {threadName}&#xD;&#xA;Extended Properties: {dictionary({key} - {value}&#xD;&#xA;)}" type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" name="Text Formatter" />

 

 </

 

formatters>

 <

logFilters>

 

<

add categoryFilterMode="DenyAllExceptAllowed" type="Microsoft.Practices.EnterpriseLibrary.Logging.Filters.CategoryFilter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" name="Category Filter1">

 

 <

 

categoryFilters>

 <

add name="General" />

 

<

add name="Debug" />

 

 <

add name="UserAuthentication" />

 

 <

add name="UnlockAccount" />

 

<

add name="Password Reset" />

 

 </

categoryFilters>

 

 </

add>

 

 <

add enabled="true" type="Microsoft.Practices.EnterpriseLibrary.Logging.Filters.LogEnabledFilter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" name="LogEnabled Filter" />

 

</

logFilters>

 

 <

categorySources>

 

 <

add switchValue="All" name="Debug" />

 

 

<

add switchValue="All" name="General">

 

 

<l

isteners>

 

 

<

add name="Database Trace Listener" />

 

 </

listeners>

 

 

</

add>

 

 

<

add switchValue="All" name="Password Reset">

 

<

listeners>

 

 

<

add name="Database Trace Listener" />

 

 </

listeners>

 

 </

add>

 

 

<

add switchValue="All" name="UnlockAccount">

 

 <

listeners>

 

 <

add name="Database Trace Listener" />

 

 </

listeners>

 

 

</

add>

 

 

<

add switchValue="All" name="UserAuthentication">

 

 <

listeners>

 

 <

add name="Database Trace Listener" />

 

 

</

listeners>

 

 </

add>

 

 

</

categorySources>

 

 <

specialSources>

 

 <

allEvents switchValue="All" name="All Events">

 

 

<

listeners>

 

 

<

add name="Database Trace Listener" />

 

 

</

listeners>

 

 </

allEvents>

 

 

<

notProcessed switchValue="All" name="Unprocessed Category">

 

 

<l

isteners>

 

 

<

add name="Database Trace Listener" />

 

 

</

listeners>

 

 

</

notProcessed>

 

 

<

errors switchValue="All" name="Logging Errors &amp; Warnings">

 

 

<

listeners>

 

 

<

add name="Database Trace Listener" />

 

 

</

listeners>

 

 </

errors>

 

 

</

specialSources>

 

 </

loggingConfiguration>

 

 

 

 

Sample code to write a log to the database

 

LogEntry le = new LogEntry();

 

 

le.EventId = 1;

le.Message =

"test from user services";

 

 

 

string userName = User.Identity.Name;

 

le.ExtendedProperties.Add(

 

"UserName", userName);

 

le.Severity = System.Diagnostics.

 

TraceEventType.Information;

 

 

le.Title =

"UserLog";

 

 

 

Logger.Write(le);



I have the above code working on the another machine but when I publish the application and test the above code, nothing get written to the database.  Please help.

Thank you!


n