Can I format the log file?

Topics: Logging Application Block
Jul 7, 2011 at 12:44 PM
Edited Jul 7, 2011 at 12:52 PM

Hi,

I cannot find the TextFormatter class in Enterprise Library Silverlight Integration Pack 5.0.

How can I format my log file? The default formatting takes much too much space and is not really nicely readable.

Here is my config file:

<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:el="clr-namespace:Microsoft.Practices.EnterpriseLibrary.Logging.Configuration;assembly=Microsoft.Practices.EnterpriseLibrary.Logging.Silverlight">
   
    <el:LoggingSettings DefaultCategory="isolated" x:Key="loggingConfiguration" LogWarningWhenNoCategoriesMatch="True">
        <el:LoggingSettings.TraceListeners>
            <el:IsolatedStorageTraceListenerData Name="isolated" RepositoryName="repTest" MaxSizeInKilobytes="2000"/>
        </el:LoggingSettings.TraceListeners>
        <el:LoggingSettings.TraceSources>
            <el:TraceSourceData Name="isolated" DefaultLevel="All">
                <el:TraceSourceData.TraceListeners>
                    <el:TraceListenerReferenceData Name="isolated"/>
                </el:TraceSourceData.TraceListeners>
            </el:TraceSourceData>
        </el:LoggingSettings.TraceSources>
    </el:LoggingSettings>
</ResourceDictionary>

 

Thanks,

Alexandra

Jul 8, 2011 at 3:30 AM

Hi,

Add this to your config:

 <el:LoggingSettings.Formatters>
            <el:TextFormatterData Name="Text Formatter" 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})}" />
 </el:LoggingSettings.Formatters>

You can remove tokens which you may think unnecessary to your application.

 

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

Jul 8, 2011 at 7:51 AM

Hi,

this doesn't work for me. It says the property 'Formatters' does not exist on the type 'LoggingSettings' in the XML namespace 'clr-namespace:Microsoft.Practices.EnterpriseLibrary.Logging.Configuration;assembly=Microsoft.Practices.EnterpriseLibrary.Logging.Silverlight'.

Which namespace should I use?

Regards,

Alexandra

Jul 8, 2011 at 9:38 AM

Hi Alexandra,

My apologies for posting the code without trying it first. Log Formatters are not yet supported in the current release of SL Integration Pack as stated under Supported Scenarios from the documentation of SL Integration Pack. The only workaround I can see here is to do the formatting yourself. You can also log this here as a feature request.

 

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

Jul 8, 2011 at 12:01 PM

Hi Noel,

How can I do the formatting by myself?

What I want to do is to have a log file as small as possible. I would like to see only a few fields in it (like timestamp, message, severity, ...)

and remove all the other fields that I don't need (like ApplicationID, EventID, Categories, ...).

Regards,

Alexandra

Jul 11, 2011 at 1:53 AM

I mean you can format the message like you can add some new line and hard coded tokens though the default tokens will still be there. Currently, the SL Integration Pack's Formatting is still limited. I suggest to log this as a feature request so Microsoft will consider it on the succeeding release.

 

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