[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 301
  • Last Modified:

vb6 -> vb.net and writing audit files

I am writing some apps that make extensive use of Audit files and wanted to know what would be considered the best practice.  Currently, we have more that 30+ copies of our app running on one server, some run as apps and some as services.  The method we use for writing audit files is to "Open, Append, Close" for each entry.  I have seen other Audit routines that open the Audit file when the App starts, Append entries during the instance life of the App (could be hours, or months) and then close the Audit file on App close.  I have also seen routines that reserve a couple Kb of space and fill it as necessary.  But this could require a lot of overhead keeping track of where the end of the entries are in the file.

Thanks
0
sidwelle
Asked:
sidwelle
  • 3
  • 3
  • 2
  • +2
4 Solutions
 
VBRocksCommented:
I would open the file, append your data, then close it immediately.

What happens if something happens to the system?  Is the server being backed up?  How does the backup system handle backing up of open files?  etc.?
0
 
planoczCommented:
The best way I have seen is to open and close your audit file when needed. You are only looking at a few seconds or less to do that to each file.
0
 
sidwelleAuthor Commented:
Is there any extra overhead associated with opening and closing the files all the time ?  Sometimes I get transactions that might have 10+ entries/second.
0
Microsoft Certification Exam 74-409

VeeamĀ® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
VBRocksCommented:
Yes, there is some overhead involved.

As an idea, you could "queue" the entries up in an list, array, datatable, or whatever, then write them out to the log at regular intervals.

0
 
planoczCommented:
Depends on how good your server is..... CPU size, etc...
0
 
sidwelleAuthor Commented:
Which method of writing files is more efficient in VB.net:
FileOpen (I noticed the upgrade wizard converted all open statements to FileOpen)
OR:  StreamWriter   ??
0
 
VBRocksCommented:
Just to append text:

    My.Computer.FileSystem.WriteAllText("filepath", "text", True)

0
 
nffvrxqgrcfqvvcCommented:
I think I would have to disagree with open,append,close. I would open the file and leave the handle open until the application is terminated. If you need to inspect the file just make sure that when you open the file handle to give FILE_SHARE_READ access. This would restrict users or other application from making any type of changes to that file. If you don't care about timestamp information on the file itself then this is probrably the best option. Typically timestamps for files are updated when the handle to them have been closed so timestamps wouldn't be updated until this occurs.
0
 
CodeCruiserCommented:
As you have multiple instances of the application running and you did not specify whether all instances write to the same file or they have their own versions, i would use a different approach. You could create a system wide MSMQ Queue. All app instances can keep queuing text to the this queue. You can then develop a separate small app (or add a separate thread which runs in one of the instances of the app) which could run at intervals(say every minute) and write all the queued text items to the audit file.
0
 
sidwelleAuthor Commented:
... you did not specify whether all instances write to the same file? : Each app writes to its own file.

Going to stay with Open, Append, Close.  You were right when you questioned, what it something happens to the server.

Thanks
0

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

  • 3
  • 3
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now