Developing a custom log system based on asp.net

Source: Internet
Author: User
Tags date config integer query system log tostring trim web services
asp.net

   This paper introduces the user log management system developed by using ASP.net and vb.net technology, realizes the dynamic management of the custom format database system, makes the management of log information more timely and efficient, and improves the work efficiency.

  keywords asp.net;vb.net; custom; log; database

  Database design for custom log management

The custom log system is a function module based on B/s development of the computer room card system in the campus network, and the background database of the system is a custom format database system. The main user tables and log tables in the database are structured as follows:

Structure fixuse ' User table
Public id as Integer ' user ID
<vbfixedarray () > public Nocard () as Byte ' card number
<vbfixedarray () > public Nouser () as Byte ' School number
<vbfixedarray (s) > public name () as Byte ' name
<vbfixedarray () > public PSW () as Byte password
Public Dept as Integer ' department ID
Public Attr as Integer ' computer room Explorer
Public Attreex as Integer ' engine room Explorer extension
Public money as Integer ' account amount
Public power as Integer ' user rights
Public Powerex as Integer ' user rights extension
Public Moneyex as Integer ' account amount extension
<vbfixedarray () > public Rev () as Byte ' system,
End Structure
Structure Fixlog ' up and down, fee-log table
Dim ID as Integer ' serial number
Dim type as Integer event type
<vbfixedarray (5) > Dim DateTime () as Byte on the start time, if the fee is null
<vbfixedarray (5) > Dim MAC () as Byte specifies the IP address of the machine
Dim ManagerID as Integer ' charge admin ID
Dim UserID as Integer ' user ID
Dim money As Integer ' consumption or fee amount Dim id_equipment As Integer ' on-machine number
<vbfixedarray (5) > Dim Datetimeend () as Byte down time
Public Location as Int64 ' system reserved
<vbfixedarray () > Dim Revex () as Byte ' reservation
End Structure

  Development principle and realization Technology of log system

  1, the Custom database development principle

Developed using the ASP.net and vb.net three-tier model to run the module as a Web application. The common three-tier development model (ASP.net model) is shown in Figure 1. The UI layer is responsible for interacting with the user, receiving input from the user and presenting the server-side data to the customer. The business logic layer is responsible for receiving requests from the browser and passing the request to the data tier while sending the request processing results to the browser. It consists of Web Forms, XML Web services, and Component Services. The Web form is the core of the ASP.net application, which is the basis for presenting data and information to customers and is the basis for responding to and handling the information and data generated by the interaction between the customer and the displayed Web form.

The System Log Management module realizes the search, statistics, analysis, illustration and printing functions of the user on the machine and the payment record.

The business logic layer is packaged in a background class library developed using vb.net.

This custom log management system functional module structure is shown in Figure 2. Because this system is for all users, including system administrators, auxiliary administrators, and ordinary students, so the function must be limited to different users.

Query the user password and balance

Query the user on the machine, the fee log

Statistics, graphics, printing, on-machine, paying fees

View the total balance of the user database
 
Reorder the log files by date order, and then write to the log file

Check a user's password, balance

Inquire

Figure 2 shows that the ordinary user login to the system, can only query statistics on the user's computer, payment information. Assistant administrators generally refer to the temporary or work-study students employed by the Computing center, who assist the Administrator in the management of the computer room. Depending on the needs of the management they have some administrative level of authority, but some important statistics they cannot get.

  2, custom log system implementation technology

2.1 Technical Details

(1) The module firstly merges the log files generated by the system in real time. Because a lot of new log files are generated every day, the system automatically retrieves new log files, and if so, merges them into the general library and indexes them by date, and deletes the merged log files.

(2) For students, administrators and their validation. In ASP.net, authentication is implemented through the authentication section of the configuration file web.config, which means that the user and password entered are correct in order to access subsequent page forms, through page form validation. Otherwise, it will point to the login page.


Session object sessions determine which level the user belongs to (the "logintype") = Logintype,logintype fetch normaluse or Normalmanager or Supermanager.

The main code for logon authentication is as follows:

Logintype = Useserver.loginin (TxtName.Text.Trim, TxtPass.Text.Trim) ' Get permission level
Session ("Logintype") = Logintype ' stores permission levels in sessions
Select Case Logintype
Case DataType.Data.LoginType.SUPUERMANAGER ' senior administrator
FormsAuthentication.RedirectFromLoginPage (txtName.Text, False)
Clsdebug.debugfileout (txtName.Text & VbTab & now.tostring)
Response.Redirect ("entertime.aspx") ' Turn to follow up page
Case DataType.Data.LoginType.NORMALMANAGER, DataType.Data.LoginType.NORMALUSER ' auxiliary Administrator or general user, to differentiate permissions by session in subsequent pages

FormsAuthentication.RedirectFromLoginPage (txtName.Text, False)
Clsdebug.debugfileout (txtName.Text & VbTab & now.tostring)
Response.Redirect ("entertime.aspx")
Case DataType.Data.LoginType.NOUSER ' user does not exist
txtName.Text = ""
Lblmsg.text = "User name does not exist"
End Select

(3) Cache users and logs. Users and log files after a period of time, usually become very large, 20M or even 40M, such large data, if each time to disk access, will take a lot of time, so must be cached, while not affecting the real-time needs of data. In ASP.net, the user object can be cached by the Cache.Insert method, and after the cache timeout, the system will automatically callback and update the cached data, thus automating the cache. We can set the timeout limit to the appsettings section of web.config.

The following is a case code for the log object cache:

Private Sub Removedcallbacklog (ByVal key as String, ByVal Value as Object, ByVal Reason as CacheItemRemovedReason) ' when the cache times out, Call this function automatically
Buildlogcache ()
End Sub
Private Sub Buildlogcache () rebuilds log cache, re-read disk data to memory
Dim useserver as Clsuseserver ' User Service object, dealing with various requirements of user data
Dim logserver as Clslogserver ' Log service object, various requirements for processing log data
Dim strusemsg as String ' information displayed to the user
Dim CacheTime as String ' log time cached in memory
Dim OnRemove as New cacheitemremovedcallback (AddressOf me.removedcallbacklog) ' Callback
Try
If IsNothing (Cache ("Useserver")) Then Buildusecache () ' If user cache is empty, rebuild user cache (User Service object in Log service object)
Useserver = CType (Cache ("Useserver"), Clsuseserver) ' Cache User Service objects
Clslogfunction.loghebin () ' Merge log files when admin logs in
Logserver = new Clslogserver (useserver) ' creates a newly created Log service object from a User service object
CacheTime = ConfigurationSettings.AppSettings ("logcachetime") ' Gets the time to cache log objects from Web.config
Cache.Insert ("Logserver", Logserver, Nothing,datetime.now.addminutes (CInt (CacheTime)), TimeSpan.Zero, Cacheitempriority.normal, onremove) ' Cache Log service objects
Catch ex as Exception
Clsdebug.debugfileout (ex. Message) ' Log exception information
End Try
End Sub

(4) The implementation of Web printing and graphics technology. Web printing is done through the ActiveReports component, which is associated with the. NET development environment is a perfect collection, providing a variety of server control through the background code to complete the data retrieval and display. The diagram is the drawing object bitmap, Graphics, pen and so on server side completes the chart, the line chart, the pie chart drawing, then uses Bitmap.save (Response.outputstream, Imageformat.gif) method to send the graph to IE in the client.

(5) Network hard disk Service module. The Dirctoryinfo, FileInfo, dirctory, file-provided objects are implemented on the server side to create and save files, directories, and so on. The client through the cookies to save the student ID is the card number, when the student first run the network hard disk service, will automatically create the student directory on the server side according to the department and the user ID, later may upload, the downloading file, the on-line editing text file and so on operation.

  Conclusion

This custom log management system is implemented as a subsystem in Suzhou University, Zhengzhou University, Henan University Campus network card system, running stably and safely, and obtains good economic benefit.



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.