Clearing the IsolatedFileStorage exceptions

Topics: Logging Application Block, Silverlight Integration Pack
Jun 13, 2011 at 1:29 AM


I would like to clear the exceptions that are being logged to the Isolated File Storage using Enterprise Library Logging block for Silverlight.

Can i use the UpdateContext and change the MaxSize to 'truncate' the file then reset the size (see code below) ?


    ''' <summary>
    ''' Clears the exceptions.
    ''' </summary>
    ''' <history>
    ''' GKrish     13/06/2011   Created
    ''' </history>
    Public Sub ClearExceptions() 
        'Get instance of the current log writer
        Dim logWriter = EnterpriseLibraryContainer.Current.GetInstance(Of LogWriter)()
        'Get the update context of the writer
        Dim updateContext = logWriter.GetUpdateContext
        'Get the trace listener update context
        Dim isoFsListener = (From traceListener In updateContext.Listeners Where traceListener.Name = "Isolated Storage Trace Listener" Select traceListener).FirstOrDefault()
        If isoFsListener IsNot Nothing Then
            With DirectCast(isoFsListener, Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.IIsolatedStorageTraceListenerUpdateContext)
                If .IsRepositoryAvailable Then
                    'remember the original size
                    Dim previousSize As Integer = .MaxSizeInKilobytes
                    .MaxSizeInKilobytes = 0 'set the size to zero to truncate it.
                    .MaxSizeInKilobytes = previousSize 'restore the size to original value
                    'only one instance can modify the update context, another instance could be locking it.
                    ExceptionHandlerUtils.HandleException(New Exception("Could not clear the exceptions because the isolated file storage repository is not available or accessible."))
                End If
            End With
            ExceptionHandlerUtils.HandleException(New Exception("There are no isolated file storage repository listeners available."))
        End If
    End Sub
Jun 13, 2011 at 9:36 AM


I have answered your similar question from another thread. I'm not sure if the above code works though I found this post mentioning that truncates only fills the repository with blank spaces.


Noel Angelo Bolasoc
Global Technologies and Solutions
Avanade, Inc.