Logging Application Block Custom Log Entry

Topics: Logging Application Block
Nov 24, 2009 at 9:39 PM

Hi,

I am setting up the Logging Application Block. i want to log into the database. In Design of Application Block 

The LogEntry class encapsulates content and associated properties for the information an application sends to the application block for logging. Your client code creates new log entries and sets properties such as the message, title, priority, severity, and event ID. Other properties, such as the process name, process ID, andThreadId, are populated by the application block. A LogEntry object also contains the ExtendedProperties property. This property is a collection of name/value pairs that allows you to place arbitrary string information into the LogEntry object. You can also create a custom LogEntry object by creating a class that derives from the LogEntry class

You must either create new formatters and trace listeners or modify the existing ones to support your custom LogEntry class.

LogEntry object has a collection of categories. The application block determines the destination for the log entry by its categories. You can also prevent the application from writing log entries with a designated category by using category filters. 

I came across Tom Blog. For creating DB Trace Listener and connecting it to a stored Procedure, how can I implement sending custom Log Entries. Using Extended Properties or Custom Classes. Which one is easier to implement and maintain?

To simplify: How to add custom fields to Logging to the DB?

Nov 25, 2009 at 1:21 AM

Using extended properties is not enough as you still need to create a custom tracelistener to write those properties to the database as well.  So I recommend create a custom database tracelistener and have your own custom log entry.  We get this question frequently so we already have a sample custom database tracelistener.  If you want, you can email us and send it you.

 

Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com

Nov 25, 2009 at 5:43 PM
Edited Nov 25, 2009 at 5:44 PM

Initially I created as in this Forum. Thats for your Suggestion. 

I went through few forums:http://www.codeplex.com/entlib/Thread/View.aspx?ThreadId=44212 having DBTrace Listener Sample. 

I am working on creating one. 

 

  [ConfigurationElementType(typeof(CustomTraceListenerData))]

    public class DBTraceListener : FormattedDatabaseTraceListener 

    { }

 

I have a question here. Do we need to Create the Attributes for StoredProc Names, DBInstance Names ?

Since we are inheriting DBTraceListener : FormattedDatabaseTraceListener from DBTraceListener will it not have the attributes by itself. 

For this, i can just access the writeLog directly and write my params there!!! What is the advantage of using this custom Trace Listener?? 

  [ConfigurationElementType(typeof(CustomTraceListenerData))]
    public class DBTraceListener : FormattedDatabaseTraceListener 
    { 

Can you also send me the sample Custom DB Trace Listener? 

 

Nov 26, 2009 at 1:15 AM

Hi,

Yes you would have to create those attribute. As far as I know, that is the way to pass additional information to the trace custom trace listener. The advantage that I can see when using the Custom Trace listener is that it can be fully integrated with the Ent lib config tool. Since that when you add a custom trace listener, the type picker looks for types from assemblies which implements "CustomTraceListener". The implementation that we have in our sample is implementing a CustomTraceListener. Hit us a mail and we'll send back the sample solution.

 

Valiant Dudan
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com

Nov 30, 2009 at 7:36 PM

Thanks for the code. I tried to create my custom trace listener based on this code. It worked. It is successfully writing to the database.

I have one more doubt. This trace listener will not have any connection with categories, filters, formatters defined in the web.config file????

Dec 1, 2009 at 4:12 AM

I believe that a custom trace listener has a property of Formatter. What specific reason that you need to have access to those properties?

Valiant Dudan
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com

Sep 26, 2010 at 10:34 AM
Edited Sep 26, 2010 at 2:26 PM

Hey guys

I have a task to put an custom log entry into a database.

can you please send me the sample code for custom listener of which you are talking above.

 

thanks

Kiran

Sep 27, 2010 at 3:02 AM

I sent a sample project not exactly the one we mentioned in the previous posting.  I created a custom log entry and did not make use of the ExtendedProperties. 

 

Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com

Sep 27, 2010 at 7:16 AM

Hello

 i have wriiten   this in the  write method

ContextLogEntry dd=new ContextLogEntry(0

dd.Appname="hen";

dd.Formname="pen";

but actually my requirement is when i click a button the data to be stored in db.

Can you please guide me

 

 

 

 



Sep 27, 2010 at 7:31 AM

Have you seen the Logging project I sent?  Have you tried to run it?  It contains the code used for logging and the configuration.  I'm not sure what specific information you need.

 

Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com

Sep 27, 2010 at 9:29 AM

I tried to run your application since we are using 4.1 i got error

so i took new application with the same copy of data mentioned in Logging application and when i run it did not give me any error but the details are not inserted  into the database

can you please help me

Sep 27, 2010 at 9:35 AM

I got  it (details are getting inserted into databse) with your application.

Sep 27, 2010 at 1:39 PM

Is it possible to display on a existing db and existing table because iam getting error when i change the script can you please help me

Sep 28, 2010 at 1:18 AM

Yes it is.  You only need to comment out the sql statements creating and altering the CustomLoggingDB database.  Comment up to the line CREATE TABLE [dbo].[Category]

 

Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com

Sep 28, 2010 at 4:12 AM

Is it possible that we restrict to create other tables like category,category log and stored procedures except writelog to be created.

Sep 28, 2010 at 4:20 AM

Yes, you just need to comment out those sql scripts.  If you won't be creating the category and category log tables, you can just comment out the code which calls the ExecuteAddCategoryStoredProcedure method in the sample project I send.

 

Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com

Sep 28, 2010 at 7:35 AM

Thanks

Can we also change the method name Executewritelogstoredprocedure to some other name because when i have tried to change it gives an error

 

can you please guide me

Sep 28, 2010 at 7:41 AM

You can change all method names in there except for the ones which have the override keywords.  If you change the method name, make sure you also update the calls to it. 

 

Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com

Nov 30, 2010 at 4:22 AM

Hi Sarah,

As per your post above can you mail me the code of sample database trace listener on my email id i.e. saxena.apurva@gmail.com.

Thanks,

Apurva

Nov 30, 2010 at 4:39 AM
Edited Nov 30, 2010 at 5:16 AM

I have sent it.  If you're unable to receive it, please provide a different email other than gmail because usually, we are unable to send email with attachments to gmail accounts.

 

Sarah Urmeneta
Global Technologies and Solutions
Avanade, Inc.
entlib.support@avanade.com

Nov 30, 2010 at 4:46 AM

Hi Sarah,

Thanks for your quick response, but can u please also mail me if you have sample code for custom text formatter also. My main logic is to customize that only but as you suggested in you above posts that i have to use custom database trace listener also for doing this. You i asked for the code.

Thanks,

Apurva

Nov 30, 2010 at 5:16 AM

I don't have a sample for that but it should be easy.  You can refer to the entlib source code and look for the TextFormatter class.  Your implementation should inherit from the LogFormatter class.  And to make it clear, it is not necessary to create a custom formatter if you have a custom database trace listener or vice versa. 

 

Sarah Urmeneta
Global Technologies and Solutions
Avanade, Inc.
entlib.support@avanade.com

Dec 22, 2010 at 4:57 PM

Hi Dudan,

Can you send me your sample application having custom log entry and custom database trace listener.

Thanks.

Suraj Shrestha

syuraj@gmail.com

 

Dec 23, 2010 at 5:12 AM

Sample sent..

Gino Terrado
Global Technologies and Solutions
Avanade, Inc.
entlib.support@avanade.com

Jun 2, 2011 at 8:25 PM

Hi Gino,

       Can you send me the above mentioned sample code having the implementation of both Custom Log Entry and Custom database trace listener.

 

 

Thanks

Naidu

vhnaidu@gmail.com

 

 

 

Jun 3, 2011 at 5:08 AM

Hi Naidu,

I've already sent the sample solution.

 

Noel Angelo Bolasoc
Global Technologies and Solutions
Avanade, Inc.
entlib.support@avanade.com

Jun 3, 2011 at 6:13 PM

Hi Noel Angelo,

                Thanks for sending the code. It worked for me.

 

 

Thanks

Naidu

Jul 12, 2011 at 4:57 PM

Hi Noel Angelo,

Could you share the sample code on how you implemented the custom database trace listener ?

 

Thanks

Jul 13, 2011 at 2:01 AM

We'll just send you the sample solution. Kindly send us a message on entlib.support@avanade.com or drop us your email here.

 

Noel Angelo Bolasoc
Global Technologies and Solutions
Avanade, Inc.
entlib.support@avanade.com

Aug 4, 2011 at 7:06 AM
AvanadeSupport wrote:

Using extended properties is not enough as you still need to create a custom tracelistener to write those properties to the database as well.  So I recommend create a custom database tracelistener and have your own custom log entry.  We get this question frequently so we already have a sample custom database tracelistener.  If you want, you can email us and send it you.

 

Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com

hello! can you please send me also a sample solution for the custom log entry and database trace listener? 

Thanks

gelaigenovesa@yahoo.com

Aug 4, 2011 at 7:56 AM

Hi,

I already send the solution. Let me know if you received it.

 

Noel Angelo Bolasoc
Global Technologies and Solutions
Avanade, Inc.
entlib.support@avanade.com

 

Aug 5, 2011 at 1:04 AM
AvanadeSupport wrote:

Hi,

I already send the solution. Let me know if you received it.

 

Noel Angelo Bolasoc
Global Technologies and Solutions
Avanade, Inc.
entlib.support@avanade.com

 

Hello, 

Got it!. Thanks. :)

Aug 11, 2011 at 11:34 AM

Hi can you send me the sample project at rajithe@gmail.com

Its a bit urgent and I have a logging project to complete.

Aug 11, 2011 at 12:50 PM

Solution sent! Let me know if you received it.

 

Noel Angelo Bolasoc
Global Technologies and Solutions
Avanade, Inc.
entlib.support@avanade.com

Aug 12, 2011 at 4:49 AM

Thanks a lot. Got it by lightning :)

Aug 18, 2011 at 8:17 PM

Please email me the Database custom trace listener.

Aug 18, 2011 at 10:52 PM
sandhu wrote:

Please email me the Database custom trace listener.


Bit urgent, need to complete a POC using that.

Aug 18, 2011 at 11:15 PM

Hi Sandhu,

 

Kindly drop us an email to  entlib.support@avanade.com so we can know where to send it. 

 

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

Aug 19, 2011 at 1:07 AM

Please send it to this email address.

I appriciate your support.

Regards,
Mohideen



From: [email removed]
To: [email removed]
Date: Thu, 18 Aug 2011 16:15:25 -0700
Subject: Re: Logging Application Block Custom Log Entry [entlib:76134]

From: AvanadeSupport
Hi Sandhu,

Kindly drop us an email to entlib.support@avanade.com so we can know where to send it.

Noel Angelo Bolasoc
Global Technologies and Solutions
Avanade, Inc.
Contact Us
Read the full discussion online.
To add a post to this discussion, reply to this email (entlib@discussions.codeplex.com)
To start a new discussion for this project, email entlib@discussions.codeplex.com
You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on CodePlex.com.
Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at CodePlex.com
Aug 19, 2011 at 1:08 AM

Please send to sm2akader@live.com

Aug 19, 2011 at 2:46 AM

Hi Mohideen,

Sorry for the late response. Kindly find the attached file for your reference. Hope this helps :)

Noel Angelo Bolasoc
Global Technologies and Solutions
Avanade, Inc.


From: Mohideen Sandhu MuzafarGani [sm2akader@live.com]
Sent: Thursday, August 18, 2011 6:07 PM
To: entlib@discussions.codeplex.com; EntLibSupport
Subject: RE: Logging Application Block Custom Log Entry [entlib:76134]


Please send it to this email address.

I appriciate your support.

Regards,
Mohideen



From: [email removed]
To: [email removed]
Date: Thu, 18 Aug 2011 16:15:25 -0700
Subject: Re: Logging Application Block Custom Log Entry [entlib:76134]

From: AvanadeSupport
Hi Sandhu,

Kindly drop us an email to entlib.support@avanade.com so we can know where to send it.

Noel Angelo Bolasoc
Global Technologies and Solutions
Avanade, Inc.
Contact Us
Read the full discussion online.
To add a post to this discussion, reply to this email (entlib@discussions.codeplex.com)
To start a new discussion for this project, email entlib@discussions.codeplex.com
You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on CodePlex.com.
Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at CodePlex.com
Sep 7, 2011 at 7:19 PM

hi,

Could you share the sample code on how you implemented the custom database trace listener ?

 my email id is : axonsuresh@yahoo.com

Sep 8, 2011 at 4:21 AM

Hi,

Can you please send the sample urgently, Because I already have implemented and got failed.

Sep 8, 2011 at 4:29 AM

Sample Sent. Let us know if you received it.

 

Noel Angelo Bolasoc
Avanade Software
Avanade, Inc.
Contact Us

Sep 8, 2011 at 4:37 AM

Thanks Noel, I have received it.

Sep 8, 2011 at 5:19 AM

Hi Noel,

  The solution which you sent is working fine. I had imported the Class Library into my Solution and when i compiled, i am getting the below error message.

 

Error    2    'CustomProvider.FullDatabaseTraceListenerData.GetCreationExpression()': no suitable method found to override    D:\UB Systems\MARS II & EAM\EAM\Unibetech.LoggingServices\FullDatabaseTraceListenerData.cs    145    64    Unibetech.LoggingServices

 

Sep 8, 2011 at 5:35 AM

Try to also import the necessary Entlib dll. (Logging.dll, Common.dll)

 

Noel Angelo Bolasoc
Avanade Software
Avanade, Inc.
Contact Us

Sep 8, 2011 at 5:51 AM

Thanks. The issue with the Version conflict with the Logging.dll. Now it is fixed.

Sep 8, 2011 at 8:25 AM

Noel,

I have imported the library to my ASP.NET solution. It works fine in my local system. But when i deploy the solution to the remote server, log entry is not going to database. It has been captured in the Event Log.

Kindly help me to override this issue.

 

 

Timestamp: 9/8/2011 8:19:48 AM

Message: Tracing to LogSource 'Database' failed. Processing for other sources will continue. See summary information below for more information. Should this problem persist, stop the service and check the configuration file(s) for possible error(s) in the configuration of the categories and sinks.


Summary for Enterprise Library Distributor Service:
======================================
-->
Message:
Timestamp: 9/8/2011 8:19:48 AM
Message: HandlingInstanceID: 3315fba4-3356-440a-b739-59ae8971ea65
An exception of type 'System.Data.SqlClient.SqlException' occurred and was caught.
----------------------------------------------------------------------------------
09/08/2011 12:19:48
Type : System.Data.SqlClient.SqlException, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
Message : The DELETE statement conflicted with the REFERENCE constraint "FK__tblProjec__AreaI__22B14FA5". The conflict occurred in database "MarsProd", table "dbo.tblProjectTerritory", column 'AreaID'.
The statement has been terminated.
Source : .Net SqlClient Data Provider
Help link :
Errors : System.Data.SqlClient.SqlErrorCollection
Class : 16
LineNumber : 10
Number : 547
Procedure : uspMasterAreaDelete
Server : svrmusstfs\ja
State : 0
ErrorCode : -2146232060
Data : System.Collections.ListDictionaryInternal
TargetSite : Void OnError(System.Data.SqlClient.SqlException, Boolean)
Stack Trace :    at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
   at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
   at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
   at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
   at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
   at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)
   at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)
   at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe)
   at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
   at Microsoft.Practices.EnterpriseLibrary.Data.Database.DoExecuteNonQuery(DbCommand command) in e:\Builds\EntLib\Latest\Source\Blocks\Data\Src\Data\Database.cs:line 443
   at Microsoft.Practices.EnterpriseLibrary.Data.Database.ExecuteNonQuery(DbCommand command) in e:\Builds\EntLib\Latest\Source\Blocks\Data\Src\Data\Database.cs:line 714
   at UnibetechDataAccessLayer.DALArea.DeleteArea(Int32 AreaId) in D:\UB VSS\UB Systems\MARS II & EAM\EAM\UnibetechDataAccessLayer\Masters\DALArea.vb:line 92
   at UnibetechBusinessLayer.BALArea.DeleteArea(Int32 AreaID) in D:\UB VSS\UB Systems\MARS II & EAM\EAM\UnibetechBusinessLayer\Masters\BALArea.vb:line 20
   at FramePages_Masters_Area.gvArea_DeleteCommand(Object source, GridCommandEventArgs e)

Additional Info:

MachineName : servername
TimeStamp : 9/8/2011 8:19:48 AM
FullName : Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
AppDomainName : /LM/W3SVC/1/Root/UBSystems-6-129599432970141668
ThreadIdentity : UNIBETONRM\sureshs
WindowsIdentity : UNIBETONRM\sureshs

Category: Database
Priority: 2
EventId: 100
Severity: Error
Title:Unibeton Exception Handling
Machine: servername
App Domain: /LM/W3SVC/1/Root/UBSystems-6-129599432970141668
ProcessId: 5928
Process Name: c:\windows\system32\inetsrv\w3wp.exe
Thread Name:
Win32 ThreadId:5648
Extended Properties: HelpLink.ProdName - Microsoft SQL Server
HelpLink.ProdVer - 09.00.4053
HelpLink.EvtSrc - MSSQLServer
HelpLink.EvtID - 547
HelpLink.BaseHelpUrl - http://go.microsoft.com/fwlink
HelpLink.LinkId - 20476

--> MachineName: servername
--> TimeStamp: 9/8/2011 8:19:48 AM
--> FullName: Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
--> AppDomainName: /LM/W3SVC/1/Root/UBSystems-6-129599432970141668
--> WindowsIdentity: NT AUTHORITY\NETWORK SERVICE

Exception Information Details:
======================================
Exception Type: System.FormatException
Message: Invalid length for a Base-64 char array.
Data: System.Collections.ListDictionaryInternal
TargetSite: Byte[] FromBase64String(System.String)
HelpLink: NULL
Source: mscorlib

StackTrace Information Details:
======================================
   at System.Convert.FromBase64String(String s)
   at Unibetech.CryptographyServices.SymmetricEncryption.DecryptDataTripleDES(String data) in D:\UB VSS\UB Systems\MARS II & EAM\EAM\Unibtech.CryptographyServices\SymmetricEncrption.cs:line 225
   at UnibetechDataAccessLayer.DatabaseGateway.DecryptConnectionString(String KeyName) in D:\UB VSS\UB Systems\MARS II & EAM\EAM\UnibetechDataAccessLayer\DatabaseGateway.vb:line 13
   at UnibetechDataAccessLayer.DatabaseGateway.CreateDatabase(String KeyName) in D:\UB VSS\UB Systems\MARS II & EAM\EAM\UnibetechDataAccessLayer\DatabaseGateway.vb:line 22
   at Unibetech.LoggingServices.BasicDatabaseTraceListener.ExecuteStoredProcedure(LogEntry logEntry) in D:\UB VSS\UB Systems\MARS II & EAM\EAM\Unibetech.LoggingServices\BasicDatabaseTraceListener.cs:line 108
   at Unibetech.LoggingServices.BasicDatabaseTraceListener.TraceData(TraceEventCache eventCache, String source, TraceEventType eventType, Int32 id, Object data) in D:\UB VSS\UB Systems\MARS II & EAM\EAM\Unibetech.LoggingServices\BasicDatabaseTraceListener.cs:line 76
   at Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.TraceListenerWrapper.TraceData(TraceEventCache eventCache, String source, TraceEventType eventType, Int32 id, Object data) in e:\Builds\EntLib\Latest\Source\Blocks\Logging\Src\Logging\TraceListeners\TraceListenerWrapper.cs:line 92
   at Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.TraceListenerWrapper.TraceData(TraceEventCache eventCache, String source, TraceEventType eventType, Int32 id, Object data) in e:\Builds\EntLib\Latest\Source\Blocks\Logging\Src\Logging\TraceListeners\TraceListenerWrapper.cs:line 92
   at Microsoft.Practices.EnterpriseLibrary.Logging.LogSource.TraceData(TraceEventType eventType, Int32 id, LogEntry logEntry, TraceListenerFilter traceListenerFilter, TraceEventCache traceEventCache) in e:\Builds\EntLib\Latest\Source\Blocks\Logging\Src\Logging\LogSource.cs:line 178
   at Microsoft.Practices.EnterpriseLibrary.Logging.LogWriterImpl.ProcessLog(LogEntry log, TraceEventCache traceEventCache) in e:\Builds\EntLib\Latest\Source\Blocks\Logging\Src\Logging\LogWriterImpl.cs:line 553

Category:

Priority: -1

EventId: 6352

Severity: Error

Title:

Machine: servername

App Domain: /LM/W3SVC/1/Root/UBSystems-6-129599432970141668

ProcessId: 5928

Process Name: c:\windows\system32\inetsrv\w3wp.exe

Thread Name:

Win32 ThreadId:5648

Extended Properties:

For more information, see Help and Support Center at http://go.microsoft.com/fwlink/events.asp.

Sep 8, 2011 at 8:30 AM

You got an sql exception which you need to get fixed first. Here is your exception message:

The DELETE statement conflicted with the REFERENCE constraint "FK__tblProjec__AreaI__22B14FA5". The conflict occurred in database "MarsProd", table "dbo.tblProjectTerritory", column 'AreaID

 

Noel Angelo Bolasoc
Avanade Software
Avanade, Inc.
Contact Us

Sep 8, 2011 at 8:30 AM

Noel, I am using the below command to raise error.

 

 ExceptionPolicy.HandleException(ExObject, "Unibetech Exception Policy")

 

In my web.config,

  <loggingConfiguration name="" tracingEnabled="true" defaultCategory="General">
    <listeners>
      <add name="Event Log Listener" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
          listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
          source="Enterprise Library Logging" formatter="Text Formatter"
          log="" machineName="." traceOutputOptions="None" />
      <add listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.CustomTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
          DatabaseInstance="LoggingConnectionString" WriteLogSp="WriteLog" AddCategorySp="AddCategory"
          type="Unibetech.LoggingServices.BasicDatabaseTraceListener, Unibetech.LoggingServices, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
          name="BasicDatabaseTraceListener" />
    </listeners>
    <formatters>
      <add type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
          template="Timestamp: {timestamp}{newline}&#xA;Message: {message}{newline}&#xA;Category: {category}{newline}&#xA;Priority: {priority}{newline}&#xA;EventId: {eventid}{newline}&#xA;Severity: {severity}{newline}&#xA;Title:{title}{newline}&#xA;Machine: {localMachine}{newline}&#xA;App Domain: {localAppDomain}{newline}&#xA;ProcessId: {localProcessId}{newline}&#xA;Process Name: {localProcessName}{newline}&#xA;Thread Name: {threadName}{newline}&#xA;Win32 ThreadId:{win32ThreadId}{newline}&#xA;Extended Properties: {dictionary({key} - {value}{newline})}"
          name="Text Formatter" />
    </formatters>
    <categorySources>
      <add switchValue="All" name="General">
        <listeners>
          <add name="Event Log Listener" />
        </listeners>
      </add>
      <add switchValue="All" name="Database">
        <listeners>
          <add name="BasicDatabaseTraceListener" />
        </listeners>
      </add>
    </categorySources>
    <specialSources>
      <allEvents switchValue="All" name="All Events" />
      <notProcessed switchValue="All" name="Unprocessed Category" />
      <errors switchValue="All" name="Logging Errors &amp; Warnings">
        <listeners>
          <add name="Event Log Listener" />
        </listeners>
      </errors>
    </specialSources>
  </loggingConfiguration>
 <exceptionHandling>
  <exceptionPolicies>
   <add name="Unibetech Exception Policy">
    <exceptionTypes>
     <add name="Exception" type="System.Exception, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
      postHandlingAction="NotifyRethrow">
      <exceptionHandlers>
       <add name="Logging Handler" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        logCategory="Database" eventId="100" severity="Error" title="Unibeton Exception Handling"
        formatterType="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.TextExceptionFormatter, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        priority="2" useDefaultLogger="false" />
      </exceptionHandlers>
     </add>
     <add name="UnauthorizedAccessException" type="System.UnauthorizedAccessException, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
      postHandlingAction="NotifyRethrow">
      <exceptionHandlers>
       <add name="Logging Handler" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        logCategory="Database" eventId="100" severity="Error" title="Unibeton Exception Handling"
        formatterType="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.TextExceptionFormatter, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        priority="1" useDefaultLogger="false" />
      </exceptionHandlers>
     </add>
     <add name="ExceptionHandlingException" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionHandlingException, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
      postHandlingAction="NotifyRethrow">
      <exceptionHandlers>
       <add name="Logging Exception Handler" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        logCategory="Database" eventId="100" severity="Error" title="Unibeton Exception Handling"
        formatterType="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.TextExceptionFormatter, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling"
        priority="0" />
      </exceptionHandlers>
     </add>
    </exceptionTypes>
   </add>
  </exceptionPolicies>
 </exceptionHandling>

Sep 8, 2011 at 8:39 AM
Edited Sep 8, 2011 at 8:41 AM

Try to look into the Sql Exception I've posted earlier. Try to check the stored procedure your database tracelistener is using. Its kind of weird that you are getting an sql exception regarding with delete since you are suppose to add records to your log table.

 

Noel Angelo Bolasoc
Avanade Software
Avanade, Inc.
Contact Us

 

 

Sep 8, 2011 at 8:43 AM

The SP's are correct. Actually, i am try to delete a record which have a reference key to another table to check the DBLog. The error which i posted above is logged into the database perfectly when i run the asp.net application from my local machine.

But the logging failed after deploying to the server.

Sep 8, 2011 at 8:54 AM
Edited Sep 8, 2011 at 8:59 AM

According to the exception, you are calling the stored procedure named "uspMasterAreaDelete". Where did you actually calling it? Is it inside your WriteLog sp? I suggest that you need to check this stored procedure and focus on fixing the exception as it seems this sp is preventing the application from logging to your database.

 

Noel Angelo Bolasoc
Avanade Software
Avanade, Inc.
Contact Us

Sep 8, 2011 at 9:00 AM

I am executing the procedure "uspMasterAreaDelete " in svrmusstfs\ja server.  this procedure is used to delete a record. so, i am try to delete a record which has reference to another table for the purpose of raising the error.

 

The same logic works when i run the application in my VS2008 development environment.

Sep 8, 2011 at 10:03 AM

The SP:uspMasterAreaDelete is called from the code and due the the reference key it throws the error. Both the transaction and logging database are in two different servers.

Sep 8, 2011 at 11:21 AM

Noel,

 This is my stored procedure script

 

Create PROCEDURE [dbo].[uspMasterAreaDelete] 
   @AreaID INT 
AS 
BEGIN 
  DELETE FROM tblArea WHERE AreaID = @AreaID 
END

 

The above procedure is called from the dotnet code which further raises the error.

Please help to solve this issue. I am breaking my head for past three days.

Sep 9, 2011 at 3:37 AM

Honestly, I'm not really sure what's going on here. I'm just referring to the exception message you have posted. If you try to not call the uspMasterAreaDelete, will you be able to log to the database?

 

Noel Angelo Bolasoc
Avanade Software
Avanade, Inc.
Contact Us

Sep 10, 2011 at 5:12 AM

Actually, I am trying to master record delete which has been referenced in another table. So, the Logic is correct.

May be do i have to register the custom database listener assembly in GAC?

Sep 10, 2011 at 6:06 AM

I try to add reference to GAC, still not working. My issue is same log is working in my development environment and it is creating entry in Log and Category Log table. but after i deployed to the web server, it is creating log only in event logger.

 

Sep 27, 2011 at 2:58 AM

Hi,

Apologies for getting back to you late. The only last thing I could suggest is to check if you are using the same configuration in dev and deployment. Just a thought.

 

Noel Angelo Bolasoc
Avanade Software
Avanade, Inc.
Contact Us

Oct 11, 2011 at 11:25 AM

Hello There:

I am using enterprise library 5.0 in our web application and our requirement is to use Logging block to

Log custom information in both rolling flat file trace listener and database trace listener. 

I have successfully configured these two listeners to log the default Text formatter template but I need to log custom information. 

Would appreciate if you could please send me the sample code for reference. 

Thanks in advance.

Oct 19, 2011 at 1:14 PM

Hi there

Could you send the sample code of the custom implementation of database trace listener with additional fields to binjie.zhao@gmail.com please? Many thanks.

Oct 20, 2011 at 7:46 AM
wheeljack wrote:

Hi there

Could you send the sample code of the custom implementation of database trace listener with additional fields to binjie.zhao@gmail.com please? Many thanks.


Hello,

Here is the sample code:

using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;
using Microsoft.Practices.EnterpriseLibrary.Logging;
using Microsoft.Practices.EnterpriseLibrary.Logging.Configuration;
using Microsoft.Practices.EnterpriseLibrary.Logging.Formatters;
using Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;

namespace SampleApplication
{
    [ConfigurationElementType(typeof(CustomTraceListenerData))]
    public class CustomDatabaseTraceListener : CustomTraceListener
    {
        public override void TraceData(System.Diagnostics.TraceEventCache eventCache, string source, System.Diagnostics.TraceEventType eventType, int id, object data)
        {
            try
            {                
                SqlDatabase db = new SqlDatabase(ConfigurationManager.ConnectionStrings["YOUR DATABASE INSTANCE NAME"].ConnectionString);
                SqlCommand cmd = new SqlCommand("STORED PROCEDURE NAME");
                cmd.CommandType = CommandType.StoredProcedure;
                //**YOU NEED TO DEFINE YOUR CUSTOM CLASS DERIVED FROM LOGENTRY HAVING EXTENDED PROPERTIES.
                CustomLogEntry customlogEntry = (CustomLogEntry)data;
                db.AddInParameter(cmd, "@FEILD1", DbType.String, customLogEntry.Field1);

                db.ExecuteNonQuery(cmd);
            }
            catch (Exception ex)
            {
                  throw ex;                
            }
        }

        public override void Write(string message)
        {
            throw new NotImplementedException();
        }

        public override void WriteLine(string message)
        {
            throw new NotImplementedException();
        }
    }

    /// <summary>
    /// Extended properties for Error Logging
    /// </summary>
    public class CustomLogEntry : LogEntry
    {
        /// <summary>
        /// Error Test
        /// </summary>
        public string Field1 { get; set; }
    }
}

Open App / Web.config file in Enterprise Library Configuration Application 
Add Logging Application Block, Add a Custom Trace Listener, Browse for the Exe / Dll where this class resides
and execute the application.
Oct 20, 2011 at 8:55 AM

Thank you very much Vaish! I will give it a go.

Oct 24, 2011 at 5:25 AM

Hi Noel,

Could you send the sample code of the custom implementation of database trace listener with additional fields to pvsnmurthy.iiitb@gmail.com or suryap@gavsin.com.

Thanks in Advance.

 

Thanks,

Murthy

Oct 31, 2011 at 4:05 AM

Hi,

I haven't received any sample code for custom implementation of database trace listener, somebody please mail me the code as its urgent for me. My email id 

 pvsnmurthy.iiitb@gmail.com or suryap@gavsin.com.

Thanks in Advance.

 

Thanks,

Murthy

Nov 3, 2011 at 12:24 PM

Hi Noel,

Could you send the sample code of the custom implementation of database trace listener with additional fields to:

noamb@satec-global.com

Thanks in Advance.

 Thanks,

Noam

Nov 15, 2011 at 9:35 AM

Hi Noel,

Can you send the sample to mlysaght at dataset dot ie

Thanks,

Michael Lysaght

Dec 4, 2011 at 11:39 AM

Dear Sarah,

           Could you send me your sample application having custom log entry and custom database trace listener.

 

Here's my emails : 

- mohamed.elmelegy@tedata.net

- eng.melegy@hotmail.com

 

Dec 6, 2011 at 12:09 PM

Dear Sarah,

could you please send me your sample application having custom log entry and custom database trace listener.

Here's my email ID :

nilecool4u@gmail.com

--Its urgent for me to make POC for client .

thanks in advance

 

Dec 14, 2011 at 6:18 PM

Hello Sarah,

Could you send the sample code of the custom implementation of database trace listener with additional fields to:

George.McCoy@MedicalSolutions.com

Thanks very much.

George

Dec 22, 2011 at 6:36 PM

Hello Sarah,

Can you send me a copy of the sample code you mention able for the database trace listener to khopkins32@hotmail.com

 

Thanks and Regards,

 

Kevin

Jan 10, 2012 at 5:37 AM

Hi Sarah,

Can you send me a copy of the sample code you mentioned for the database trace listener to p_boopathi@hotmail.com

 

Thanks and Regards,

 

Boopathi

Jan 10, 2012 at 6:08 AM

Take a look at the Extended Properties Trace Listener with Custom Exception Handler project here.

--
Randy Levy
Enterprise Library support engineer
entlib.support@live.com 

Jan 27, 2012 at 12:47 AM

Hi Sarah,

Could you mail me the code of sample database trace listener on my email willy.martinez@ielsoft.com.

Thanks,

Jan 27, 2012 at 5:53 AM

Hi Sarah,
Dare I ask you to send me the code of the sample database trace listener to michal.puza@seznam.cz ?
Thanks in advance, Michal

Feb 20, 2012 at 6:30 AM


Hi Noel /Sarah,
Request you to send me  the custom implementation of database trace listener with additional fields to:

emailabhay@rediffmail.com

Thanks.
abhay

Mar 12, 2012 at 1:48 PM
Edited Mar 12, 2012 at 1:48 PM

Hello Sarah

Could you please dend to me custom implementation of database trace listener with additional fields to:

darkair@gmail.com

Thanks!!!!

Felipe Albacete

Mar 12, 2012 at 7:17 PM

Is here!!

 

Thanks!!!!

 

Felipe Albacete

Mar 20, 2012 at 2:40 PM

Hello,

 

Can you please send the example code.... custom implementation of databasetracelistener with additional fields to 

immadisettypavan1986@gmail.com.

 

Thanks in advance.

 

Pavan

May 8, 2012 at 12:31 PM

Hello Noel / Sarah!

Here comes another request for the sample project having a custom LogEntry and a custom database trace listener.

Please send to: el_huevo_electronico@hotmail.com

Many thanks in advance,

Jens 

 

Jun 9, 2012 at 3:13 AM

Hello Noel and Sarah. I sent an email earlier today requesting the sample solution that includes the custom database listener used to add more columns to the exiting Log table. I have seen the sample that partitions the extended properties to a separate table (Extended Properties Trace Listener with Custom Exception Handler), but I believe I need the one referenced in this thread. Could you please send it via my profile? I also emailed the support mailbox directly earlier today, but got a reply suggesting I use the forum instead.

Thanks,

JF

Jun 9, 2012 at 5:53 AM

@jfrysinger, if you go the Sample Projects page you will see a Custom Database Trace Listener project that adds an additional column to the Log table and uses a custom LogEntry to populate that column.

If you want to add another column you would have to:

  1. Add a new Property to the CustomLogEntry
  2. Add another parameter on the CustomLogEntry constructor
  3. Extract the new Property in the CustomDatabaseTraceListener.ExecuteWriteLogStoredProcedure method
  4. Add the new Property value as a database command parameter
  5. Add a new parameter to the WriteLog stored procedure
  6. Add the new parameter to the insert statement in the WriteLog stored procedure
  7. Add a new column to the database

--
Randy Levy
Enterprise Library support engineer
entlib.support@live.com