Best way to write log file

P

Pablo Tola

Hi, I'm developing a site statistics application, now it's in testing and I
get a very high CPU usage on the aspnet_wp.exe, I think it's because the way
I'm writing the log file, I'm using XML to do it, Which is the best way to
do it, I'm including a portion of the code so you can see what I'm doing...

Dim objXmlDoc As New XmlDataDocument
objXmlDoc.Load(strLogFullPath)

Dim root As XmlNode = objXmlDoc.DocumentElement

Dim LastNode As XmlNode = root.LastChild
Dim strLId As String

If LastNode Is Nothing Then
strLId = "1"
Else
strLId = LastNode.Item("Id").InnerText + 1
End If

Dim PageView As XmlElement =
objXmlDoc.CreateElement("PageView")

Dim Id As XmlElement = objXmlDoc.CreateElement("Id")
Dim SiteId As XmlElement = objXmlDoc.CreateElement("SiteId")
Dim PageViewDate As XmlElement =
objXmlDoc.CreateElement("PageViewDate")
Dim SessionId As XmlElement =
objXmlDoc.CreateElement("SessionId")
Dim CookieId As XmlElement =
objXmlDoc.CreateElement("CookieId")
Dim PageName As XmlElement =
objXmlDoc.CreateElement("PageName")
Dim Referral As XmlElement =
objXmlDoc.CreateElement("Referral")
Dim IP As XmlElement = objXmlDoc.CreateElement("IP")
Dim Browser As XmlElement =
objXmlDoc.CreateElement("Browser")
Dim Screen As XmlElement = objXmlDoc.CreateElement("Screen")
Dim UserAgent As XmlElement =
objXmlDoc.CreateElement("UserAgent")
Dim CountryCode As XmlElement =
objXmlDoc.CreateElement("CountryCode")
Dim TimeZone As XmlElement =
objXmlDoc.CreateElement("TimeZone")

Id.InnerText = CType(strLId, String)
SiteId.InnerText = CType(intSiteId, String)
PageViewDate.InnerText = CType(dtmDateTime, String)
SessionId.InnerText = CType(intSessionId, String)
CookieId.InnerText = CType(intCookieId, String)
PageName.InnerText = strPageName
Referral.InnerText = strReferral
IP.InnerText = strIP
Browser.InnerText = strBrowser
Screen.InnerText = strScreen
UserAgent.InnerText = strUserAgent
CountryCode.InnerText = strCountryCode
TimeZone.InnerText = CType(intTimeZone, String)

PageView.AppendChild(Id)
PageView.AppendChild(SiteId)
PageView.AppendChild(PageViewDate)
PageView.AppendChild(SessionId)
PageView.AppendChild(CookieId)
PageView.AppendChild(PageName)
PageView.AppendChild(Referral)
PageView.AppendChild(IP)
PageView.AppendChild(Browser)
PageView.AppendChild(Screen)
PageView.AppendChild(UserAgent)
PageView.AppendChild(CountryCode)
PageView.AppendChild(TimeZone)

root.AppendChild(PageView)

objXmlDoc.Save(strLogFullPath)

Any help is greatly appreciated, thank you.

(e-mail address removed)
 
G

Guest

You can create a Log object, ie LogValue that has the properties PageViewDate, SiteId, CookieId, etc. ... you then set the properties of the object just like you would any other object. You can then use XML serialization to serialize the object to a stream and write it out. It will be much more efficient than building the XML file by hand.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top