bypass error messages on my installed app
bypass error messages on my installed app
bypass error messages on my installed app
bypass error messages on my installed app
bypass error messages on my installed app
bypass error messages on my installed app bypass error messages on my installed app bypass error messages on my installed app bypass error messages on my installed app bypass error messages on my installed app bypass error messages on my installed app bypass error messages on my installed app bypass error messages on my installed app
bypass error messages on my installed app bypass error messages on my installed app
bypass error messages on my installed app
Go Back  Xtreme Visual Basic Talk > > > bypass error messages on my installed app


Reply
 
Thread Tools Display Modes
  #21  
Old 01-10-2011, 09:39 AM
pampam686 pampam686 is offline
Freshman
 
Join Date: Nov 2010
Posts: 33
Default


how do i turn on logging again?
Reply With Quote
  #22  
Old 01-10-2011, 11:30 AM
AtmaWeapon's Avatar
AtmaWeaponbypass error messages on my installed app AtmaWeapon is offline
Fabulous Florist

Forum Leader
* Guru *
 
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,500
Default

You write code that outputs log information to a file. There's no real automatic logging because it is impossible for a tool to predict where you want log information.

You can also use the tracing features of the .NET Framework, but it takes a heck of a lot more reading to come up with a solution roughly equivalent to the kind of solution having a log file would create.

Here's a sample that implements a simple logging class; it is not the best implementation by any means and is quite messy, but it will get the job done:
Code:
Imports System.IO

Public Class Logger

    Private Const ApplicationName As String = "Your Application Name"
    Private Const LogFileName As String = "log.txt"

    Private Shared _writer As StreamWriter

    Public Shared Sub StartLog()
        InitializeLogIfNeeded()

        Dim header = String.Format("{0}{0}------{0}Log started at {1}...{0}", Environment.NewLine, DateTime.Now)
        _writer.WriteLine(header)

        CloseLog()
    End Sub

    Public Shared Sub WriteLine(ByVal logMessage As String)
        InitializeLogIfNeeded()

        If _writer IsNot Nothing Then
            Dim message As String = String.Format("[{0}] {1}", DateTime.Now, logMessage)
            _writer.WriteLine(message)
        End If

        CloseLog()
    End Sub

    Private Shared Sub CloseLog()
        If _writer IsNot Nothing Then
            _writer.Close()
            _writer = Nothing
        End If
    End Sub

    Private Shared Function GetLogPath() As String
        Dim appDataPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
        Dim applicationDirectoryPath = Path.Combine(appDataPath, ApplicationName)

        If Not Directory.Exists(applicationDirectoryPath) Then
            Try
                Directory.CreateDirectory(applicationDirectoryPath)
            Catch ex As Exception
                ' The right thing to do here is complicated. This version won't log if the
                ' directory can't be created.
                Return Nothing
            End Try
        End If

        Return Path.Combine(applicationDirectoryPath, LogFileName)
    End Function

    Private Shared Sub InitializeLogIfNeeded()

        If _writer Is Nothing Then
            Dim logPath = GetLogPath()
            If logPath Is Nothing Then
                Return
            End If

            _writer = New StreamWriter(logPath, append:=True)
        End If
    End Sub

End Class
Here's a small sample of an application that uses it:
Code:
Module Module1

    Sub Main()
        Logger.StartLog()
        Logger.WriteLine("Test")
        Logger.WriteLine("Test2")
    End Sub

End Module
You don't *have* to call StartLog() before using it, but it helps separate different runs if you do. Calling it once in a form's Load event handler is probably sufficient.
__________________
.NET Resources
My FAQ threads | Tutor's Corner | Code Library
I would bet money 2/3 of .NET questions are already answered in one of these three places.
Reply With Quote
  #23  
Old 01-10-2011, 11:32 AM
AtmaWeapon's Avatar
AtmaWeaponbypass error messages on my installed app AtmaWeapon is offline
Fabulous Florist

Forum Leader
* Guru *
 
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,500
Default

You write code that outputs log information to a file. There's no real automatic logging because it is impossible for a tool to predict where you want log information.

You can also use the tracing features of the .NET Framework, but it takes a heck of a lot more reading to come up with a solution roughly equivalent to the kind of solution having a log file would create.

Here's a sample that implements a simple logging class; it is not the best implementation by any means and is quite messy, but it will get the job done:
Code:
Imports System.IO

Public Class Logger

    Private Const ApplicationName As String = "Your Application Name"
    Private Const LogFileName As String = "log.txt"

    Private Shared _writer As StreamWriter

    Public Shared Sub StartLog()
        InitializeLogIfNeeded()

        Dim header = String.Format("{0}{0}------{0}Log started at {1}...{0}", Environment.NewLine, DateTime.Now)
        _writer.WriteLine(header)

        CloseLog()
    End Sub

    Public Shared Sub WriteLine(ByVal logMessage As String)
        InitializeLogIfNeeded()

        If _writer IsNot Nothing Then
            Dim message As String = String.Format("[{0}] {1}", DateTime.Now, logMessage)
            _writer.WriteLine(message)
        End If

        CloseLog()
    End Sub

    Private Shared Sub CloseLog()
        If _writer IsNot Nothing Then
            _writer.Close()
            _writer = Nothing
        End If
    End Sub

    Private Shared Function GetLogPath() As String
        Dim appDataPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
        Dim applicationDirectoryPath = Path.Combine(appDataPath, ApplicationName)

        If Not Directory.Exists(applicationDirectoryPath) Then
            Try
                Directory.CreateDirectory(applicationDirectoryPath)
            Catch ex As Exception
                ' The right thing to do here is complicated. This version won't log if the
                ' directory can't be created.
                Return Nothing
            End Try
        End If

        Return Path.Combine(applicationDirectoryPath, LogFileName)
    End Function

    Private Shared Sub InitializeLogIfNeeded()

        If _writer Is Nothing Then
            Dim logPath = GetLogPath()
            If logPath Is Nothing Then
                Return
            End If

            _writer = New StreamWriter(logPath, append:=True)
        End If
    End Sub

End Class
Here's a small sample of an application that uses it:
Code:
Module Module1

    Sub Main()
        Logger.StartLog()
        Logger.WriteLine("Test")
        Logger.WriteLine("Test2")
    End Sub

End Module
You don't *have* to call StartLog() before using it, but it helps separate different runs if you do. Calling it once in a form's Load event handler is probably sufficient. On a Windows 7/Vista system, the log file will be at "C:\Users\<username>\AppData\Roaming\Your Application Name\log.txt". On XP, it'd be more like "C:\Documents and Settings\<username>\Application Data\Roaming\Your Application Name\log.txt". (You should change the "Your Application Name" string constant to something more appropriate for your application.
__________________
.NET Resources
My FAQ threads | Tutor's Corner | Code Library
I would bet money 2/3 of .NET questions are already answered in one of these three places.
Reply With Quote
  #24  
Old 01-10-2011, 11:58 AM
pampam686 pampam686 is offline
Freshman
 
Join Date: Nov 2010
Posts: 33
Default

how do i enable/view logging again?
Reply With Quote
  #25  
Old 01-11-2011, 07:14 AM
PlausiblyDamp's Avatar
PlausiblyDampbypass error messages on my installed app PlausiblyDamp is offline
Ultimate Contributor

Forum Leader
* Expert *
 
Join Date: Nov 2003
Location: Newport, Wales
Posts: 2,058
Default

Quote:
Originally Posted by pampam686 View Post
how do i enable/view logging again?
Did you read Atma's post at all? He went to the trouble of showing you how you could implement logging and you have seemingly ignored him.
__________________
Intellectuals solve problems; geniuses prevent them.
-- Albert Einstein

Posting Guidelines Forum Rules Use the code tags
Reply With Quote
  #26  
Old 01-11-2011, 07:42 AM
pampam686 pampam686 is offline
Freshman
 
Join Date: Nov 2010
Posts: 33
Default

i was just about to say i have read what he said
Reply With Quote
  #27  
Old 01-11-2011, 09:24 AM
AtmaWeapon's Avatar
AtmaWeaponbypass error messages on my installed app AtmaWeapon is offline
Fabulous Florist

Forum Leader
* Guru *
 
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,500
Default

I say no, you didn't read what I said. It explained the answer to your question in full detail. There's not a shorter answer, if that's what you're fishing for. The errors aren't going to go away by magic. You're going to have to do some work to hunt them down and fix them. Part of that work involves doing more than a quick skim of people's responses. I don't write a page of text with examples because I want to confuse; I do it because I want to explain. If you can't be bothered to read the responses to your questions and ask questions about the parts that confuse you, I think you'll find few people willing to write responses.
__________________
.NET Resources
My FAQ threads | Tutor's Corner | Code Library
I would bet money 2/3 of .NET questions are already answered in one of these three places.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
bypass error messages on my installed app
bypass error messages on my installed app
bypass error messages on my installed app bypass error messages on my installed app
bypass error messages on my installed app
bypass error messages on my installed app
bypass error messages on my installed app bypass error messages on my installed app bypass error messages on my installed app bypass error messages on my installed app bypass error messages on my installed app bypass error messages on my installed app bypass error messages on my installed app
bypass error messages on my installed app
bypass error messages on my installed app
 
bypass error messages on my installed app
bypass error messages on my installed app
 
-->