Share via


Sample: Web Log Analyzer for ReportViewer

Download sample

The Web Log Analyzer sample is a Windows form application that analyzes log files created by Web servers, such as Microsoft Internet Information Server (IIS). It includes reports that show statistics on page hits, server activity, and referrals from other sites.

Web Log Analyzer includes functionality that allows you to configure the files that are included in the analysis. You can select log files that are generated by your Web server and filter out specific file types.

This sample is available in Visual Basic. To copy all of the sample files to your computer, click the Disk button at the top of the page. To view a single file, select the file name and click the View button. Not all of the sample files can be viewed directly from this page. Sample files that are located in folders do not appear in the list.

This topic explains how to run and modify the sample. It also includes optional instructions for modifying a table in a report. Tables are composed of multiple parts. Each part has its own properties and actions (for example, to add a column, you must select an adjacent column). To learn more about tables, see Adding Table Data Regions (Visual Studio Report Designer). For more information about other samples and developer walkthroughs, see Samples and Walkthroughs.

Note

Before opening MainForm.vb, be sure to build the application first.

To run the sample

  1. Open WebLogAnalyzer.sln in Visual Studio 2008.

  2. Press F5 to compile and run the sample. When the application starts up, a sample log file included in the project is analyzed and the results are displayed in the form of tables and charts. You can use different log files from your computer to view actual data.

  3. In Web Log Analyzer, select Open Log Files from the File menu. By default, Web logs are stored in the C:\Windows\System32\LogFiles\W3SVC1 directory.

  4. Select the folder that contains the log files, and then click OK. The application reads all log files in the selected folder, analyzes the data, and displays results.

  5. (Optional) You can filter out file types that you do not want to analyze (for example, image files and stylesheets). To do this, go to the View menu and select Ignore Files. In the dialog box, type a list of file extensions to ignore, separated by commas. Click OK. To refresh the report, reopen the log files by selecting Open Log Files from the File menu.

    Try the options on the ReportViewer toolbar to see how printing, searching, and page navigation is done. The main report includes a document map used to navigate to specific sections of the report. You can open the document map through the ReportViewer toolbar.

To change the text displayed in the Title Bar

  1. In Solution Explorer, right-click MainForm.vb and choose View Designer.

  2. In the Properties window, make sure that MainForm is selected in the drop-down list, then locate and change the value of Text property. For example, change "Web Log Analyzer" to "<Your Company Name> Web Log Analyzer" to customize the text.

  3. The Text property of the form is changed when you press ENTER. Notice that the Title Bar of the form reflects your new text.

To add 3D effect to charts

  1. In Solution Explorer, double-click MainReport.rdlc to open the report.

  2. Right-click on the chart and select Properties.

  3. In the Chart Properties dialog box, switch to the 3D Effect tab.

  4. Select Display chart with 3D Visual Effect.

  5. Use the sliders to rotate the 3-D chart.

  6. Click OK to close the dialog box.

To change the color of the bars in the chart

  1. In Solution Explorer, double-click MainReport.rdlc to open the report.

  2. Right-click on the chart and select Properties.

  3. Switch to the Data tab and click the Edit button next to the Values list.

  4. In the Edit Chart Value dialog, switch to the Appearance tab.

  5. Click the Series Style button to open the Style Properties dialog.

  6. Switch to the Fill tab and select the new colors.

  1. In Solution Explorer, double-click MainReport.rdlc.

  2. Click on the table under the "Most popular pages" title. The various selectors of the table become visible.

  3. Right-click on the row selector of the detail row, and select Edit Group.

  4. In the Details Grouping dialog box, select the Filters tab. In the Value column of the first filter, enter the number of rows to display. Note that the value must start with an equal sign (=) in order to be interpreted as a number rather than a text string.

To display most frequent referrers to your Web sites

  1. In Solution Explorer, double-click LogFileEntry.vb.

  2. Find the LogFileEntry class and add a Referrer property:

    Public ReadOnly Property Referrer() As String
        Get
            Return m_referrer
        End Get
    End Property
    
  3. From the Build menu, click Build WebLogAnalyzer to make sure there are no errors.

  4. In Solution Explorer, expand the Reports folder and double-click MainReport.rdlc.

  5. Scroll to the bottom of the report, and then drag the bottom edge of the report body upwards to make room for a new table.

  6. From the Toolbox, drag a table onto the report.

  7. By default the table has three columns. You can delete the last column because it is not needed. Right-click on the column heading of the last column and click Delete.

  8. Resize the columns to fit the data. You can drag the column border to resize it. Shorten the width of the second column; it only needs to accommodate a number. You can widen the first column to use the remaining space in the table.

  9. From the Data menu, select Show Data Sources. The Data Sources window displays the public properties of the LogFileEntry class. Notice that the newly added Referrer property is also visible.

  10. From the Data Sources window, drag the Referrer property onto the detail row of the first column in the table (the detail row is the middle row). Notice that the header row is automatically filled with a default column header.

  11. Right-click on the row selector of the detail row and choose Edit Group.

  12. In the Details Grouping dialog, click on the first row of the Group on table. From the drop-down list, select =Fields!Referrer.Value.

  13. In the Details Grouping dialog, switch to the Filters tab. In the Expression column, type =CountRows(). In the Operator column, choose Top N. In the Value column, type =10 and then click OK to close the dialog.

  14. In the second column of the table, type Referrals in the header row and type =CountRows() in the detail row .

  15. Right-click on the table selector and select Properties.

  16. In the Table Properties dialog, switch to the Sorting tab. In the Expression column, type =CountRows() and in the Direction column choose Descending.

  17. Optionally, you can filter out specific referrers, such as your own site. In the Table Properties dialog, switch to Filters tab. In the Expression column, type =Fields!Referrer.Value.StartsWith("http://mysite"). (Replace "http://mysite" with the URL of your site.) In the Operator column, choose =. In the Value column, type =false.

  18. Optionally, specify fonts, colors, and borders for the header and detail rows and the table in the Properties window.

  19. Build the application to view your changes.

Requirements

You must have Microsoft Visual Studio 2008 with the Visual Basic compiler.

Web logs from IIS provide the data used in the reports. The sample includes a static data file so that you can run the sample. If you want to use log files from your Web server, you must have access to an instance of IIS.

Demonstrates

The source code demonstrates:

  1. Creation of client report definition (.rdlc) files that include charts, tables, document maps, and more.

  2. Creation of a ReportViewer control that runs reports from within a Windows form.

  3. Use of the ReportRefresh and Drillthrough methods of the ReportViewer class.

  4. Use of the LocalReport and DocumentMapCollapsed properties of the ReportViewer class.

  5. Use of the DataSources of the LocalReport class.

  6. Use of the GetDocumentMap method of the Report class.