5 Replies - 111 Views - Last Post: 07 February 2020 - 02:14 PM Rate Topic: -----

#1 aspfun   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 135
  • Joined: 16-January 13

Output error message to a txt file

Posted 07 February 2020 - 01:23 PM

I used code below to display an error on the screen.
I want to create a txt file error.txt and insert error messages into it.
Where will add error.txt file be?
I tried to put error.txt under project name or under bin folder but none of them working

Try
'''some code here
Catch ex As Exception
       MsgBox(ex.Message & " in Main_load")
 End Try 

Is This A Good Question/Topic? 0
  • +

Replies To: Output error message to a txt file

#2 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15476
  • View blog
  • Posts: 62,006
  • Joined: 12-June 08

Re: Output error message to a txt file

Posted 07 February 2020 - 01:45 PM

I would make a static class that writes out to a given location. Typically in a folder 'logs' right off the execution path. Then call the static 'write error' in the catches.

What have you attempted?
Was This Post Helpful? 0
  • +
  • -

#3 aspfun   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 135
  • Joined: 16-January 13

Re: Output error message to a txt file

Posted 07 February 2020 - 01:54 PM

View Postmodi123_1, on 07 February 2020 - 01:45 PM, said:

I would make a static class that writes out to a given location. Typically in a folder 'logs' right off the execution path. Then call the static 'write error' in the catches.

What have you attempted?


After compiled (F5) project of Winform, I just simply copy contents in ./bin/debug/ (Including all dll files and exe file) to a file server. To have all users read error messages, I want to insert errors into error.txt.
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15476
  • View blog
  • Posts: 62,006
  • Joined: 12-June 08

Re: Output error message to a txt file

Posted 07 February 2020 - 01:56 PM

Ok? :dontgetit:
Was This Post Helpful? 0
  • +
  • -

#5 Martyr2   User is offline

  • Programming Theoretician
  • member icon

Reputation: 5519
  • View blog
  • Posts: 14,520
  • Joined: 18-April 07

Re: Output error message to a txt file

Posted 07 February 2020 - 01:58 PM

I assume you are working in VB.NET and not VB 6 right? If VB.NET, make sure you use MessageBox.Show and not MsgBox(). That is legacy and will eventually go away.

As for the text file, you can put it under the project name or bin/debug folder (remember it depends on which mode aka Release/Debug you are in). It just matters how you are creating/reading it. There are different ways to get paths to where things might be. One way is shown below...

pathToAssembly = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)



Here we are getting the directory of the executable. This is also something like...

Directory.GetCurrentDirectory()



This gets the current directory. I would start by trying out a few of these lines, print out what they show and then once you find the location you want, put your error.txt there and then you will have the path to it.

Edit: Writing is then just a matter of writing...

https://docs.microso...-a-streamwriter

:)

This post has been edited by Martyr2: 07 February 2020 - 01:59 PM

Was This Post Helpful? 0
  • +
  • -

#6 aspfun   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 135
  • Joined: 16-January 13

Re: Output error message to a txt file

Posted 07 February 2020 - 02:14 PM

View PostMartyr2, on 07 February 2020 - 01:58 PM, said:

I assume you are working in VB.NET and not VB 6 right? If VB.NET, make sure you use MessageBox.Show and not MsgBox(). That is legacy and will eventually go away.

As for the text file, you can put it under the project name or bin/debug folder (remember it depends on which mode aka Release/Debug you are in). It just matters how you are creating/reading it. There are different ways to get paths to where things might be. One way is shown below...

pathToAssembly = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)



Here we are getting the directory of the executable. This is also something like...

Directory.GetCurrentDirectory()



This gets the current directory. I would start by trying out a few of these lines, print out what they show and then once you find the location you want, put your error.txt there and then you will have the path to it.

Edit: Writing is then just a matter of writing...

https://docs.microso...-a-streamwriter

:)/>


Thank you so much for advises.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1