EntLib 5 - log method not writing to database, but not erroring out either

Topics: Exception Handling Application Block, Logging Application Block
Aug 9, 2011 at 3:41 PM

Hi all -

Any suggestions on why my Log is not writing to my database?  All seems to check out and I'm not getting any errors, but nothing shows in my Log.

 

Calling method - This calls another class inside my solution, but I am able to debug to this method and it looks like it works.

MPA.Common.Logger.Log("xxx", LogPriority.DetailedInfo, LogCategory.BL);

 

App.config - for my client solution.  The Logger class from above is actually part of another Class Library project that has no config.

<?xml version="1.0"?>
<configuration>
  <configSections>
   <section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
   <section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
   <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
      <section name="MPA.Client.UI.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
    </sectionGroup>
  </configSections>


	<loggingConfiguration name="Logging Application Block" tracingEnabled="true"
	   defaultCategory="General" logWarningsWhenNoCategoriesMatch="true">
		<listeners>
			<add name="Database Listener" type="Microsoft.Practices.EnterpriseLibrary.Logging.Database.FormattedDatabaseTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging.Database"
			  listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Database.Configuration.FormattedDatabaseTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging.Database"
			  databaseInstanceName="mydB" writeLogStoredProcName="WriteLog"
			  addCategoryStoredProcName="AddCategory" formatter="Text Formatter"
			  traceOutputOptions="None" filter="All" />
			<add name="Formatted EventLog TraceListener" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging"
			  listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging"
			  source="Enterprise Library Logging" formatter="Text Formatter"
			  log="Application" machineName="" traceOutputOptions="None" filter="All" />
		</listeners>
  <formatters>
   <add type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging"
    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;)}"
    name="Text Formatter" />
  </formatters>
  <categorySources>
   <add switchValue="All" name="All Events">
    <listeners>
     <add name="Database Listener" />
		
    </listeners>
   </add>
  </categorySources>
  <specialSources>
   <allEvents switchValue="All" name="All Events">
    <listeners>
     <add name="Database Listener" />
    </listeners>
   </allEvents>
   <notProcessed switchValue="All" name="Unprocessed Category" />
   <errors switchValue="All" name="Logging Errors &amp; Warnings">
    <listeners>
     <add name="Database Listener" />
    </listeners>
   </errors>
  </specialSources>
 </loggingConfiguration>
 <dataConfiguration defaultDatabase="mydB" />
 <connectionStrings>
  <add name="mydB" connectionString="Database=mydBInstance;Server=xxxx;User id=xxxx;Password=xxxx;"
   providerName="System.Data.SqlClient" />
  <add name="mydB2" connectionString="Database=mydBInstance2;Server=xxxx;User id=xxxx;Password=xxxx;"   providerName="System.Data.SqlClient" /> </connectionStrings>
 <appSettings>
  <add key="SiteName" value="xxxx" />
  <add key="ClientSettingsProvider.ServiceUri" value="" />
 </appSettings>
 <system.serviceModel>
    <behaviors>
      <endpointBehaviors>
        <behavior name="MPAServiceClientBehavior">
          <clientCredentials>
            <windows allowNtlm="true" />
          </clientCredentials>
          <dataContractSerializer maxItemsInObjectGraph="10000000" />
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <bindings>
      <netTcpBinding>
        <binding name="netTcpBindingConfiguration" sendTimeout="00:02:00" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647">
          <readerQuotas maxStringContentLength="2147483647" maxArrayLength="2147483647" />
        </binding>
      </netTcpBinding>
    </bindings>
   ... 


Tahnks in advance for any support you can provide,
Brent

 

Aug 10, 2011 at 3:58 AM

Hi Brent,

Have you checked if your connection string is really working? I suggest you point your Logging Errors and Warnings Category to a flat file to see if there are any exceptions generated. Your config may look like below:

Special Sources

 

Noel Angelo Bolasoc
Global Technologies and Solutions
Avanade, Inc.
Contact Us

 

Aug 10, 2011 at 4:57 AM

Hi Noel -

I attempted to copy what you had, but have not seen any writes yet and get the following error (see commented area, in green) when debugging:

    public class Logger
    {
        public static string Title = "XXX Log";

        public static void Log(string message, LogPriority priority, LogCategory categroy)
        {
            // ERROR IS ENCOUNTERED ON LogEntry INSTANTIATION
            LogEntry log = new LogEntry();
            log.Title = Title;
            log.Message = message;
            log.Categories.Add(categroy.ToString());
            log.Priority = (int)priority;
            WriteLog(log);       
        }

 

My generated EntLib/app.config settings:

Ent Lib settings

 

What do you think?

thanks again,
Brent

 

 

 

I even changed the "All Events" section to point to my newly created Rolling Flat File Trace Listener.


Aug 10, 2011 at 6:13 AM

Can you tell us what the error is?

 

Noel Angelo Bolasoc
Global Technologies and Solutions
Avanade, Inc.
Contact Us

Aug 10, 2011 at 6:20 AM

Sorry about that.  Error:

Aug 10, 2011 at 6:31 AM

Do you have already the Entlib Source on your machine? Can you try clicking that "Browse To Find Source" link then when a dialog opens, point it to EntLib50Src\Blocks\Logging, and see if this works? By the way, the default path of Entlib Source is on My Documents.

 

Noel Angelo Bolasoc
Global Technologies and Solutions
Avanade, Inc.
Contact Us

Aug 10, 2011 at 6:50 AM

Yes, have source on my machine. 

And am embarassed to say that I didn't know where it was.  So I did this and was able to proceed with client exeuction; however, I never saw any files getting generated.  I thought maybe they are going somewhere else other than the \Debug directory, but a search gets nothing either.

Aug 10, 2011 at 7:11 AM

I haven’t gotten a chance to sincerely tell you how much I appreciate your assistance. I hope to repay the favor in the future … at minimum, with my working solutions.

Have a great day,

Brent

From: AvanadeSupport [email removed]
Sent: Tuesday, August 09, 2011 10:32 PM
To: Yager, Brent L
Subject: Re: EntLib 5 - log method not writing to database, but not erroring out either [entlib:268384]

From: AvanadeSupport

Do you have already the Entlib Source on your machine? Can you try clicking that "Browse To Find Source" link then when a dialog opens, point it to EntLib50Src\Blocks\Logging, and see if this works? By the way, the default path of Entlib Source is on My Documents.

Noel Angelo Bolasoc
Global Technologies and Solutions
Avanade, Inc.
Contact Us