0

We have been using Enterprise Library 3.1 to log exceptions to external files using our own custom listener. Recently we needed to create a class library that uses our custom listener but this class library will be called from a vendor application so we will not have control of the vendors config file. I have used the following articles to log exceptions with the built in Enterprise Library listeners but when I try to use our custom trace listener it does not work. I do not receive an error, it just does not create the file. If I add the custom listener to the vendors config listeners section then it all works fine.

My first thought is that the ExceptionPolicyFactory is loading the correct external config file but the factory is not reading the "type" from the listeners section in the external config.

Can anyone help point me in the right direction on how to completely move the "listeners" section into an external config file when using a custom listener?

Entlib and interop: does it work, and where does the config file go? http://blogs.msdn.com/b/tomholl/archive/2006/04/02/entlib2externalconfig.aspx http://hugoribeiro.blog.com/2009/05/15/no-configuration-enterprise-library/

Basically this section needs moved into the external config file.

<configuration>
  <configSections>
    <section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0, Culture=neutral, PublicKeyToken=fe5b8e7d42f3f6e1" />
  </configSections>
  <loggingConfiguration name="Logging Application Block" tracingEnabled="false"
      defaultCategory="Error Category" logWarningsWhenNoCategoriesMatch="true">
    <listeners>
      <add fileName="C:\LOGS\Error.log" listenerDataType="Test.Logging.Configuration.TestTraceListenerData, Test.Logging, Version=1.5.0.0, Culture=neutral, PublicKeyToken=fe5b8e7d42f3f6e1"
              traceOutputOptions="None" type="Test.Logging.TraceListeners.TestTraceListener, Test.Logging, Version=1.5.0.0, Culture=neutral, PublicKeyToken=fe5b8e7d42f3f6e1"
              name="Error Log TraceListener" />
    </listeners>
    <formatters>
      <add template="Timestamp: {timestamp}&#xD;&#xA;Application Domain: {appDomain} | Machine: {machine}&#xD;&#xA;Extended Properties: {dictionary({key} - {value}&#xD;&#xA;)}&#xD;&#xA;Message: {message}&#xD;&#xA;Process Name: {processName}&#xD;&#xA;"
              type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0, Culture=neutral, PublicKeyToken=fe5b8e7d42f3f6e1"
              name="Error Detail Text Formatter" />
    </formatters>
    <specialSources>
      <errors switchValue="All" name="Logging Errors &amp; Warnings">
        <listeners>
          <add name="Error Log TraceListener" />
        </listeners>
      </errors>
    </specialSources>
  </loggingConfiguration>
</configuration>

Well I have narrowed the problem down a little more. It seems that in my ExceptionHandler class has a method called "WriteToLog" and inside that method is the Logger.Write(LogEntry). The Logger is an Enterprise logger and will not work without creating a LogWriterFactory and the LogWriterFactory requires a ConfigurationSource.

So now the question is... How do I pass in the ConfigurationSource or my own custom Logger or even the config file location into my ExceptionHandeler class?

Community
  • 1
  • 1
goroth
  • 2,510
  • 5
  • 35
  • 66

2 Answers2

0

I've had a similar problem with Log4Net and it turned out that it wasn't anything to do with the config. Instead the directory where the file was supposed to be created did not have the appropriate permissions for the file to get created. Check that the NTFS permissions on the directory where the file should get created has Read, Write and Modify for the appropriate user.

groksrc
  • 2,910
  • 1
  • 29
  • 29
  • The directory permissions are fine. I am able to write the file when the listener section is in the vendors config file but not when it is in a external config file. – goroth Jan 29 '13 at 19:10
0

In my logger object I ended up get the config file by using GetExecutingAssembly Location.

Spontifixus
  • 6,570
  • 9
  • 45
  • 63
goroth
  • 2,510
  • 5
  • 35
  • 66