Enterprise Library Logging Application Block

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • arunairs@gmail.com

    Enterprise Library Logging Application Block

    Hi,

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

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

    listenerDataTyp e="Microsoft.Pr actices.Enterpr iseLibrary.Logg ing.Configurati on.FlatFileTrac eListenerData,
    Microsoft.Pract ices.Enterprise Library.Logging , Version=4.0.0.0 ,
    Culture=neutral , PublicKeyToken= 31bf3856ad364e3 5"
    traceOutputOpti ons="Timestamp" filter="All"
    type="Microsoft .Practices.Ente rpriseLibrary.L ogging.TraceLis teners.FlatFile TraceListener,
    Microsoft.Pract ices.Enterprise Library.Logging , Version=4.0.0.0 ,
    Culture=neutral , PublicKeyToken= 31bf3856ad364e3 5"
    name="FlatFile TraceListener" />
    </listeners>
    <formatters>
    <add template="Times tamp: {timestamp}&#xD ;&#xA;Message :
    {message}&#xD;& #xA;Category: {category}&#xD; &#xA;Priorit y:
    {priority}&#xD; &#xA;EventId : {eventid}&#xD;& #xA;Severity:
    {severity}&#xD; &#xA;Title:{tit le}&#xD;&#xA;Me thod:
    {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;Threa d Name: {threadName}&#x D;&#xA;Extende d
    Properties: {dictionary({ke y} - {value}&#xD;&#x A;)}"

    type="Microsoft .Practices.Ente rpriseLibrary.L ogging.Formatte rs.TextFormatte r,
    Microsoft.Pract ices.Enterprise Library.Logging , Version=4.0.0.0 ,
    Culture=neutral , PublicKeyToken= 31bf3856ad364e3 5"
    name="Text Formatter" />
    </formatters>
    <categorySource s>
    <add switchValue="Al l" name="General">
    <listeners>
    <add name="FlatFile TraceListener" />
    </listeners>
    </add>
    </categorySources >
    <specialSources >
    <allEvents switchValue="Al l" name="All Events" />
    <notProcessed switchValue="Al l" name="Unprocess ed Category" />
    <errors switchValue="Al l" name="Logging Errors &amp; Warnings">
    <listeners>
    <add name="FlatFile TraceListener" />
    </listeners>
    </errors>
    </specialSources>
    </loggingConfigur ation>

    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<Custome r,
    IDomainEntity>( "Arun", null);
    string res = customer.Valida te();

    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\P IABTest\PIABTes t\bin\Debug
    \PIABTest.vshos t.exe
    Thread Name:
    Win32 ThreadId:16656
    Extended Properties:
    Timestamp=12107 455156919
    ----------------------------------------
    ----------------------------------------
    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\P IABTest\PIABTes t\bin\Debug
    \PIABTest.vshos t.exe
    Thread Name:
    Win32 ThreadId:16656
    Extended Properties:
    Timestamp=12107 458102597
    ----------------------------------------

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

    thanks,

    Arun
  • mesut

    #2
    Re: Enterprise Library Logging Application Block

    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)
    {
    SetMasterPagePr operty(AppConst ants.ErrorMessa ge,
    ex.Message);
    ex.Data.Add("Me thod Name: ", "btnInsert_Clic k()");
    Boolean rethrow;
    rethrow = ExceptionPolicy .HandleExceptio n(ex,
    AppConstants.UI Policy);
    }



    Comment

    Working...