Customize Consent Preferences

We use cookies to help you navigate efficiently and perform certain functions. You will find detailed information about all cookies under each consent category below.

The cookies that are categorized as "Necessary" are stored on your browser as they are essential for enabling the basic functionalities of the site. ... 

Always Active

Necessary cookies are required to enable the basic features of this site, such as providing secure log-in or adjusting your consent preferences. These cookies do not store any personally identifiable data.

No cookies to display.

Functional cookies help perform certain functionalities like sharing the content of the website on social media platforms, collecting feedback, and other third-party features.

No cookies to display.

Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics such as the number of visitors, bounce rate, traffic source, etc.

No cookies to display.

Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.

No cookies to display.

Advertisement cookies are used to provide visitors with customized advertisements based on the pages you visited previously and to analyze the effectiveness of the ad campaigns.

No cookies to display.

Microsoft Silverlight – Error Logging to Isolated Storage

Isolated storage location is under

C:Users*username*AppDataLocalLowMicrosoftSilverlightis

To handle error logging in Silverlight, create a clsIsolatedStorage.vb

Imports System.IO
Imports System.Xml
Imports System.IO.IsolatedStorage
Imports MyApplication.clsApplicationGlobal
    Public Class clsIsolatedStorage
        Shared Sub ErrorHandler(ByVal mMode As String, ByVal Procedure As String, ByVal e As Exception)
            Try
                WriteToXML(mMode, Procedure, e)
            Catch ex As Exception
                ‘Big Problem
            End Try
        End Sub

        Shared Sub WriteToXML(ByVal mmode As String, ByVal mproc As String, ByVal e As Exception 
            Try
                Using store As IsolatedStorageFile = _
                IsolatedStorageFile.GetUserStoreForApplication()
                    ‘ Create a directory for the files
                    ‘ if it doesn’t already exist. subDirName As String = "SLErrors"
                    If Not store.DirectoryExists(subDirName) Then
                        store.CreateDirectory(subDirName)
                    End If
                End Using

                Dim isoStore As IsolatedStorageFile = _ 
                IsolatedStorageFile.GetUserStoreForApplication()
                ‘ Create/Open file
                Dim isoStream As IsolatedStorageFileStream = _
                New IsolatedStorageFileStream("" & subDirName & "" & "ErrorLog.txt", _
                FileMode.Append, FileAccess.Write, isoStore) "" FileMode.Append, FileAccess.Write
                ‘ Write to the Isolated Storage for the user.

                Using streamWriter As StreamWriter = New StreamWriter(isoStream 
                    Dim settings As XmlWriterSettings = New XmlWriterSettings()
                    settings.Indent = True
                    ‘ Create an XmlWriter.
                    Using writer As XmlWriter = XmlWriter.Create(streamWriter, settings)
                        writer.WriteStartElement("Error")
                        writer.WriteElementString("DateTime", Now)
                        writer.WriteElementString("Module", mmode)
                        writer.WriteElementString("Procedure", mproc)

                        If IsNothing(e) = False Then writer.WriteElementString("ExceptionMessage", e.Message 
                        writer.WriteEndElement()
                        writer.Flush()
                    End Using
                End Using
                isoStream.Close()
                ‘ Open the file again for reading.
                ‘Using reader As New StreamReader(isoStore.OpenFile("SLErrorLog.txt", FileMode.Open))
                ‘ HoldErrors = HoldErrors & reader.ReadToEnd()
                ‘End Using
            Catch ex As Exception
            End Try
        End Sub
    End Class

To use the class:

Private eMod As String = "PageName"
Private eProc As String = ""

Private Sub btnSameAddress_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs 
    eProc = "btnSameAddress_Click"
    Try
        txtAddress.Text = HoldReporterStreet
        txtApartment.Text = HoldReporterApt
        txtCity.Text = HoldReporterCity
        txtState.Text = HoldReporterState
        txtZip.Text = HoldReporterZip
		
    Catch ex As Exception
        clsIsolatedStorage.ErrorHandler(eMod, eProc, ex)
 
    End Try
    txtAddress.Focus()
End Sub

I have a clsApplicationGlobal that holds variables that I use from one page to the next. You may be able to put the public shared in the clsIsolatedStorage as a private variable.

MyApplication_Silverlight_Application.clsApplicationGlobal
 
Public Shared subDirName As String = "SLErrors"

Leave a Reply