• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 170
  • Last Modified:

Open log files based on paths stored in array

I am writing a web application that parses log files created by another application. In one particular section of the log collection the parent folder and names of the log files are dynamically generated to include the server name in the files and the server names for their parent directories. For example:

C:\data\StorageSystem\StorageSystemA\StorageSystemA_Log1.log
C:\data\StorageSystem\StorageSystemA\StorageSystemA_Log2.log
C:\data\StorageSystem\StorageSystemB\StorageSystemB_Log1.log
C:\data\StorageSystem\StorageSystemB\StorageSystemB_Log2.log
C:\data\StorageSystem\Server123\Server123_Log1.log
C:\data\StorageSystem\Server123\Server123_Log2.log

I have for loops written to collect the folder names and the full log file name/path of each log file of interest located in each directory. The number of possible directories that need to be added to the array is 6 and the number of log files is also 6 (I only need data from one log in each directory). Since there are up to 6 possible tables needed to display the data from the log files I'm assuming the best method to do this is to create the controls dynamically?

The part I'm stuck on at the moment is how to manage placing controls and dropping the data into the controls. Ideally for each file read i would like to generate a table with 2 rows and 3 colums in each row to display the data.


'Loop through the Storage System sub-folders and list folders and files.
        Dim storage As String = txtPath.Text & "\StorageSystem\"
        Dim folderString As String = ""
        For Each folder As String In Directory.GetDirectories(storage)
            folderString &= folder.ToString
            folderString &= vbCrLf
            txtTest.Text = folderString
        Next

        'Dim fileString As String = ""
        For Each storageFile As String In IO.Directory.GetFiles(txtPath.Text & "\StorageSystem\", "*_SlotConfigInfo.log", SearchOption.AllDirectories)
            'Dim txtBoxForData As New TextBox()
            'Me.Controls.Add(txtBoxForData)
            Dim data As String() = IO.File.ReadAllLines(storageFile)
            Dim systemName As String = data(4).Substring(14)
            Dim systemID As String = data(6).Substring(12)
            Dim systemModel As String = data(8).Substring(15)
            Dim systemSerialNumber As String = data(14).Substring(23)
            Dim cpuCount As String = data(30).Substring(23)
            Dim memorySize As String = data(32).Substring(14)

            'fileString &= storageFile.ToString
            'fileString &= vbCrLf
            txtTest2.Text = systemName & vbCrLf & systemID & vbCrLf & systemModel & vbCrLf & systemSerialNumber & vbCrLf & cpuCount & vbCrLf & memorySize
        Next

Open in new window

0
newimagent
Asked:
newimagent
  • 6
  • 4
1 Solution
 
CodeCruiserCommented:
Can you not use a grid or other similar control?
0
 
newimagentAuthor Commented:
I guess i could..... Ill have to look into that tonight.
0
 
newimagentAuthor Commented:
I am unable to find a good resource that explains how I can bind the specific variables above into a grid view for each log file. Can you help?
0
Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

 
CodeCruiserCommented:
You would not deal with variables. You can loop through the files and fill a datatable. Google for csv to datatable or i will post a link when i get to a computer.
0
 
newimagentAuthor Commented:
Right but I don't want the whole file I only want pieces. it's easy to do this with sql queries, but I see no information on how to do this when you are only looking for a 10 specific pieces of data in a log file that contains thousands.
0
 
CodeCruiserCommented:
Is it a csv file? You can loop through the file and only put the info in datatable that you want.
0
 
newimagentAuthor Commented:
no it is a very oddly formatted file. i'm not sure what you would call it. Open the file in word pad and without word wrap its a single line of what seems like double tab delimited entries, open in notepad and it appears as a standard file if you disable word wrap it turns into a single line and if you re-enable word wrap it completely screws up the formatting.

I have attached the file the above code is pulling the data from for reference ... if it helps.

This is why i'm thinking dynamically generating tables, lables, and textboxes to display the data is probably the best way to do it, but my searches are not turning up how I can do this outside of a sql datasource.

I am open to options though if anyone know a better or easier way that will still put the data on screen in an organized and easy to read format.
10.10.1.200-SlotConfigInfo.log
0
 
CodeCruiserCommented:
You can use the same code as above but instead of variables, fill a datatable. Here is an example

Dim dTable as New DataTable
DTable.columns.add("col1", gettype(string))
DTable.columns.add("col2", gettype(string))

For each line as string in io.file.readalllines("path")
Dim words as string() = line.split(":")
Dim drow as datarow = dtable.newrow()
Drow(0) = words(0)
Drow(1)= words(1)
Dtable.rows.add(drow)
Next

This is just an example and you will need to tweak this code. Now whether you have 1 line or 1000 lines, you wont have to worry about the variables and controls. Once datatable is filled, use it as a datasource of the grid.
0
 
newimagentAuthor Commented:
This reads all of the log data into the data table. How can I parse out the pieces i'm looking for?

I used the following code below, which works for the first row, I just need to figure out how to make it loop though each folder and add a row to the datatable for each target. it seems like i need an &= or something similar to concatenate each iteration to the datagrid? .... I'm just not sure at this point.

The code below successfully pulls the data from the first log file present and displays it in the gridview.
'Loop through the Storage System sub-folders and list folders and files.
        Dim storage As String = txtPath.Text & "\StorageSystem\"
        If Directory.Exists(storage) Then
            Dim folderString As String = ""
            For Each folder As String In Directory.GetDirectories(storage)
                folderString &= folder.ToString
                folderString &= vbCrLf
                txtTest.Text = folderString
            Next

            'Dim fileString As String = ""
            For Each slotConfigInfo As String In IO.Directory.GetFiles(txtPath.Text & "\StorageSystem\", "*_SlotConfigInfo.log", SearchOption.AllDirectories)
                For Each versionInfo As String In IO.Directory.GetFiles(txtPath.Text & "\StorageSystem\", "*_VersionInfo.log", SearchOption.AllDirectories)
                    'Dim txtBoxForData As New TextBox()
                    'Me.Controls.Add(txtBoxForData)
                    Dim slotConfigData As String() = IO.File.ReadAllLines(slotConfigInfo)
                    Dim versionInfoData As String() = IO.File.ReadAllLines(versionInfo)
                    Dim systemName As String = slotConfigData(4).Substring(14)
                    Dim systemID As String = slotConfigData(6).Substring(12)
                    Dim systemModel As String = slotConfigData(8).Substring(15)
                    Dim systemSerialNumber As String = slotConfigData(14).Substring(23)
                    Dim cpuCount As String = slotConfigData(30).Substring(23)
                    Dim memorySize As String = slotConfigData(32).Substring(14)
                    Dim ontapVersion As String = versionInfoData(2).Substring(24, 9)

                    'fileString &= storageFile.ToString
                    'fileString &= vbCrLf
                    txtTest2.Text = systemName & vbCrLf & systemID & vbCrLf & systemModel & vbCrLf & systemSerialNumber & vbCrLf & cpuCount & vbCrLf & memorySize & vbCrLf & ontapVersion

                    'Create "FilerData" Data Table
                    Dim Table1 As DataTable
                    Table1 = New DataTable("FilerData")
                    'Declare 1 Row for data
                    Dim Row1 As DataRow

                    Try
                        'Declare column called Filer Name
                        Dim filerName As DataColumn = New DataColumn("Filer Name")
                        'Set Data Type for the column
                        filerName.DataType = System.Type.GetType("System.String")
                        'Add column to table
                        Table1.Columns.Add(filerName)

                        Dim filerModel As DataColumn = New DataColumn("Model")
                        filerModel.DataType = System.Type.GetType("System.String")
                        Table1.Columns.Add(filerModel)

                        Dim Ontap As DataColumn = New DataColumn("Ontap")
                        Ontap.DataType = System.Type.GetType("System.String")
                        Table1.Columns.Add(Ontap)

                        Dim sysID As DataColumn = New DataColumn("SysID")
                        sysID.DataType = System.Type.GetType("System.String")
                        Table1.Columns.Add(sysID)

                        Dim sysSerial As DataColumn = New DataColumn("Serial")
                        sysSerial.DataType = System.Type.GetType("System.String")
                        Table1.Columns.Add(sysSerial)

                        Dim sysMem As DataColumn = New DataColumn("Memory")
                        sysMem.DataType = System.Type.GetType("System.String")
                        Table1.Columns.Add(sysMem)

                        Dim sysCPU As DataColumn = New DataColumn("CPU")
                        sysCPU.DataType = System.Type.GetType("System.String")
                        Table1.Columns.Add(sysCPU)

                        'Declare new row
                        Row1 = Table1.NewRow()
                        'Fill row with data - Item property is used to set the field value
                        Row1.Item(filerName) = systemName
                        Row1.Item(filerModel) = systemModel
                        Row1.Item(Ontap) = ontapVersion
                        Row1.Item(sysID) = systemID
                        Row1.Item(sysSerial) = systemSerialNumber
                        Row1.Item(sysMem) = memorySize
                        Row1.Item(sysCPU) = cpuCount
                        Table1.Rows.Add(Row1)

                    Catch ex As Exception

                    End Try

                    Dim ds As New DataSet()
                    ds = New DataSet()
                    'creating a dataset
                    ds.Tables.Add(Table1)
                    'adding the table to dataset
                    gridFilerProperties.DataSource = ds
                    gridFilerProperties.DataBind()
                    'binding the table to datagrid

                Next
            Next

        Else


        End If

Open in new window

0
 
newimagentAuthor Commented:
'Create "FilerData" Data Table
        Dim Table1 As DataTable
        Table1 = New DataTable("FilerData")
        'Declare column called Filer Name
        Dim filerName As DataColumn = New DataColumn("Filer Name")
        'Set Data Type for the column
        filerName.DataType = System.Type.GetType("System.String")
        'Add column to table
        Table1.Columns.Add(filerName)

  Try
                'Declare new row
                Row1 = Table1.NewRow()
                'Fill row with data - Item property is used to set the field value
                Row1.Item(filerName) = systemName

                Table1.Rows.Add(Row1)

            Catch ex As Exception

            End Try
0

Featured Post

Granular recovery for Microsoft Exchange

With Veeam Explorer for Microsoft Exchange you can choose the Exchange Servers and restore points you’re interested in, and Veeam Explorer will present the contents of those mailbox stores for browsing, searching and exporting.

  • 6
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now