2
votes

Using Enterprise Library 5.0 Logging Block in .NET 4.0 which is the only Block I am using I was trying to customize information being logged to include Call Stack, calling Assembly name and perhaps Line Numbers. So I went to text Formatter that I created and added a few entries:

Method: {property(MethodName)}{newline}
Call Stack:{property(CallStack)}

so after that matching text formatter config file entry now looks like this:

    <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} &#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})}{newline}&#xA;Method: {property(MethodName)}{newline}&#xA;Call Stack:{property(CallStack)}"
            name="Text Formatter" />
    </formatters>

You can see new added entries in there. But when I run it my logging entries look like this:

----------------------------------------
Timestamp: 12/15/2011 9:51:48 PM 
Message: Starting up the application

Category: General

Priority: -1

EventId: 0

Severity: Information

Title:

Machine: HCCLI066

App Domain: WindowsFormsApplicationTest1.vshost.exe

ProcessId: 2488

Process Name: C:\Projects\WindowsFormsApplicationTest1\bin\Debug\WindowsFormsApplicationTest1.vshost.exe

Thread Name: 

Win32 ThreadId:2636

Extended Properties: 

Method: <Error: property MethodName not found>

Call Stack:<Error: property CallStack not found>

Is there anything else I need to do to see those properties logged? How do I add completely custom property, like "Line Numbers" for example?

1
Dear Victor, Could you please explain how you solved this issue to show the call stack information using the text formatter? ThanksMohamed Ramadan

1 Answers

0
votes

This article does a bit more than you need, but it's reliable:

http://www.codeproject.com/KB/architecture/DistributedLogging.aspx

Another I found:

http://www.dotnetscraps.com/dotnetscraps/post/how-to-configure-and-use-the-logging-application-block.aspx

The later applies to 4.1, but it's probably a good place to start and then verify against the MSDN documentation for "Whats New" in 5.0 with the Log Block.