Enterprise Library Logging Application Block

A

arunairs

Hi,

Using the EnterpriseLibrary 4.0, is it possible to Log the method
name in the log file.

I have it cofigured thus:
<loggingConfiguration name="Logging Application Block"
tracingEnabled="true"
defaultCategory="General" logWarningsWhenNoCategoriesMatch="true">
<listeners>
<add fileName="trace.log"
header="----------------------------------------"
footer="----------------------------------------" formatter=""

listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FlatFileTraceListenerData,
Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.0.0.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35"
traceOutputOptions="Timestamp" filter="All"
type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FlatFileTraceListener,
Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.0.0.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35"
name="FlatFile TraceListener" />
</listeners>
<formatters>
<add template="Timestamp: {timestamp}
Message:
{message}
Category: {category}
Priority:
{priority}
EventId: {eventid}
Severity:
{severity}
Title:{title}
Method:
{method}
Machine: {machine}
Application Domain:
{appDomain}
Process Id: {processId}
Process Name:
{processName}
Win32 Thread Id:
{win32ThreadId}
Thread Name: {threadName}
Extended
Properties: {dictionary({key} - {value}
)}"

type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter,
Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.0.0.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35"
name="Text Formatter" />
</formatters>
<categorySources>
<add switchValue="All" name="General">
<listeners>
<add name="FlatFile TraceListener" />
</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="FlatFile TraceListener" />
</listeners>
</errors>
</specialSources>
</loggingConfiguration>

My Interface ios configured thus:

public interface IDomainEntity
{
[Tag("Log")]
string Validate();
}

I am using the Policy Injection App Block thus

IDomainEntity customer = PolicyInjection.Create<Customer,
IDomainEntity>("Arun", null);
string res = customer.Validate();

I want to log the method name too (in his case Validate()) to the log
file. Currently my app spits out the following log file:
----------------------------------------
General Information: 0 : Timestamp: 10/3/2008 9:53:57 AM
Message:
Category: General
Priority: -1
EventId: 0
Severity: Information
Title:Call Logging
Machine: PSI-2503-ARUN
App Domain: PIABTest.vshost.exe
ProcessId: 60620
Process Name: E:\MyProjects\PIABTest\PIABTest\bin\Debug
\PIABTest.vshost.exe
Thread Name:
Win32 ThreadId:16656
Extended Properties:
Timestamp=12107455156919
----------------------------------------
----------------------------------------
General Information: 0 : Timestamp: 10/3/2008 9:53:58 AM
Message:
Category: General
Priority: -1
EventId: 0
Severity: Information
Title:Call Logging
Machine: PSI-2503-ARUN
App Domain: PIABTest.vshost.exe
ProcessId: 60620
Process Name: E:\MyProjects\PIABTest\PIABTest\bin\Debug
\PIABTest.vshost.exe
Thread Name:
Win32 ThreadId:16656
Extended Properties:
Timestamp=12107458102597
----------------------------------------

How do I include the method name too in each log entry?

thanks,

Arun
 
M

mesut

I'm not sure if there is a kewyord for the method name to put in the
configuration, but I use Extended property in Exception handler and
that works fine see below...

catch (Exception ex)
{
SetMasterPageProperty(AppConstants.ErrorMessage,
ex.Message);
ex.Data.Add("Method Name: ", "btnInsert_Click()");
Boolean rethrow;
rethrow = ExceptionPolicy.HandleException(ex,
AppConstants.UIPolicy);
}
 
A

arqta

you can use tracer in enterprise logging which will output method name but I am bot sure about the performance issues
void EnterpriseLogging()
{
using (new Tracer("myCategoryWhichHasSomeListeners"))
{
for (int i = 0; i < 3; i ++)
{
LogEntry log = new LogEntry();
log.Message = string.Format("inside method");
log.Categories.Add("General");
Logger.Write(log);
}
}
}

it will out put something like this plus some more but you can see method name here

***********
Timestamp: 02/12/2009 10:36:23
Message: Start Trace: Activity '06655cba-64d5-46d4-8972-62e18dd5ddf4' in method 'TestCommonLogging.LoggerDemo.EnterpriseLogging' at 2420031256604 ticks
Category: myCategoryWhichHasSomeListeners
Priority: 5
EventId: 1
Severity: Start
Title:TracerEnter
Machine: FD-T5400-21
Application Domain: TestCommomLogging.vshost.exe
Process Id: 3348
Process Name: C:\...\TestCommomLogging.vshost.exe
Win32 Thread Id: 5380
Thread Name:
Extended Properties: 5



mesut wrote:

I'm not sure if there is a kewyord for the method name to put in
04-Oct-08

I'm not sure if there is a kewyord for the method name to put in th
configuration, but I use Extended property in Exception handler an
that works fine see below..

catch (Exception ex

SetMasterPageProperty(AppConstants.ErrorMessage
ex.Message)
ex.Data.Add("Method Name: ", "btnInsert_Click()")
Boolean rethrow
rethrow = ExceptionPolicy.HandleException(ex
AppConstants.UIPolicy)
}

Previous Posts In This Thread:

Enterprise Library Logging Application Block
Hi

Using the EnterpriseLibrary 4.0, is it possible to Log the metho
name in the log file

I have it cofigured thus
<loggingConfiguration name="Logging Application Block
tracingEnabled="true
defaultCategory="General" logWarningsWhenNoCategoriesMatch="true"
<listeners
<add fileName="trace.log
header="----------------------------------------
footer="----------------------------------------" formatter="

listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FlatFileTraceListenerData
Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.0.0.0
Culture=neutral, PublicKeyToken=31bf3856ad364e35
traceOutputOptions="Timestamp" filter="All
type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FlatFileTraceListener
Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.0.0.0
Culture=neutral, PublicKeyToken=31bf3856ad364e35
name="FlatFile TraceListener" /
</listeners
<formatters
<add template="Timestamp: {timestamp}
Message
{message}
Category: {category}
Priority
{priority}
EventId: {eventid}
Severity
{severity}
Title:{title}
Method
{method}
Machine: {machine}
Application Domain
{appDomain}
Process Id: {processId}
Process Name
{processName}
Win32 Thread Id
{win32ThreadId}
Thread Name: {threadName}
Extende
Properties: {dictionary({key} - {value}
)}

type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter
Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.0.0.0
Culture=neutral, PublicKeyToken=31bf3856ad364e35
name="Text Formatter" /
</formatters
<categorySources
<add switchValue="All" name="General"
<listeners
<add name="FlatFile TraceListener" /
</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="FlatFile TraceListener" /
</listeners
</errors
</specialSources
</loggingConfiguration

My Interface ios configured thus

public interface IDomainEntity
{
[Tag("Log")]
string Validate();
}

I am using the Policy Injection App Block thus

IDomainEntity customer = PolicyInjection.Create<Customer,
IDomainEntity>("Arun", null);
string res = customer.Validate();

I want to log the method name too (in his case Validate()) to the log
file. Currently my app spits out the following log file:
----------------------------------------
General Information: 0 : Timestamp: 10/3/2008 9:53:57 AM
Message:
Category: General
Priority: -1
EventId: 0
Severity: Information
Title:Call Logging
Machine: PSI-2503-ARUN
App Domain: PIABTest.vshost.exe
ProcessId: 60620
Process Name: E:\MyProjects\PIABTest\PIABTest\bin\Debug
\PIABTest.vshost.exe
Thread Name:
Win32 ThreadId:16656
Extended Properties:
Timestamp=12107455156919
----------------------------------------
----------------------------------------
General Information: 0 : Timestamp: 10/3/2008 9:53:58 AM
Message:
Category: General
Priority: -1
EventId: 0
Severity: Information
Title:Call Logging
Machine: PSI-2503-ARUN
App Domain: PIABTest.vshost.exe
ProcessId: 60620
Process Name: E:\MyProjects\PIABTest\PIABTest\bin\Debug
\PIABTest.vshost.exe
Thread Name:
Win32 ThreadId:16656
Extended Properties:
Timestamp=12107458102597
----------------------------------------

How do I include the method name too in each log entry?

thanks,

Arun

I'm not sure if there is a kewyord for the method name to put in
I'm not sure if there is a kewyord for the method name to put in the
configuration, but I use Extended property in Exception handler and
that works fine see below...

catch (Exception ex)
{
SetMasterPageProperty(AppConstants.ErrorMessage,
ex.Message);
ex.Data.Add("Method Name: ", "btnInsert_Click()");
Boolean rethrow;
rethrow = ExceptionPolicy.HandleException(ex,
AppConstants.UIPolicy);
}


Submitted via EggHeadCafe - Software Developer Portal of Choice
WPF DataGrid as ComboBox Dropdown
http://www.eggheadcafe.com/tutorial...3e-b8b35d738842/wpf-datagrid-as-combobox.aspx
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top