By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,423 Members | 1,601 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,423 IT Pros & Developers. It's quick & easy.

Enterprise Library Logging Application Block

P: n/a
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.EnterpriseLi brary.Logging.Configuration.FlatFileTraceListenerD ata,
Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.0.0.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35"
traceOutputOptions="Timestamp" filter="All"
type="Microsoft.Practices.EnterpriseLibrary.Loggin g.TraceListeners.FlatFileTraceListener,
Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.0.0.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35"
name="FlatFile TraceListener" />
</listeners>
<formatters>
<add 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;Method:
{method}&#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;)}"

type="Microsoft.Practices.EnterpriseLibrary.Loggin g.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
Oct 3 '08 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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);
}

Oct 3 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.