By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,058 Members | 1,209 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,058 IT Pros & Developers. It's quick & easy.

Creating A log File for Web Services?

P: n/a
Below is a routine I use for creating log files. It works great on most VB
Applications. However, for web services, it needs some help. The problem
is I cant reflect properly into a web service to find out where the .DLL is.
As is, this code writes a log file ok, but the log file ends up buried
directory deep inside the .Net Framework directories. Anyone know how to
find the path of a web service .DLL so I can fix this code to write to the
"bin" directory where the Web Service Dll is?
Public Function get_name_of_application(Optional ByVal
IncludeFullPathOfExe As Boolean = False) As String
Dim Application_Directory As String
Dim Asm As System.Reflection.Assembly = _
System.Reflection.Assembly.GetExecutingAssembly

Dim strConfigLoc As String = Asm.Location
If Not IncludeFullPathOfExe Then
strConfigLoc = GetFileNameOnly(Asm.Location)
End If

get_name_of_application = strConfigLoc.ToString
End Function

Public Sub COMMON_Module_Print(ByVal MyMessage As String, Optional ByVal
WriteToFile As Boolean = False)
Try
Static TodaysDate As Date = Now

Debug.WriteLine(MyMessage)

If WriteToFile Then
Dim OutputLogFileName As String =
get_name_of_application(True) & ".Log"
COMMON_FILE_Module.FILE_AppendFile(MyMessage,
OutputLogFileName)

If Now.Date < TodaysDate.Date Then
'Archive OutputFile
Dim ArchivedFileName As String = OutputLogFileName &
".Archived." & Now.Date.ToShortDateString.Replace("/", "-")
FILE_ForceMove(OutputLogFileName, ArchivedFileName)
TodaysDate = Now
End If

End If

Catch ex As Exception
RaiseEvent Mod_Print("COMMON_Module_Print: " & ex.Message)
End Try
End Sub
Nov 21 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
This is how I do it:

Imports System.Web.Services
Imports System.IO
Imports System.Xml

<WebService(Namespace:="http://<blah.blah>/<blah>")> _
Public Class <blah>
Inherits WebService

Private m_appfolder As String
Private m_appname As String

Public Sub New()

MyBase.New()

InitializeComponent()

m_appname = Context.Request.ServerVariables.Item("path_transla ted")

m_appfolder = Path.GetDirectoryName(m_appname)

m_appname = Path.GetFileNameWithoutExtension(m_appname)

' Other code here

End Sub

' Other methods here

End Class

I then have a stock standard config file in the same directory as the
<blah>.asmx.vb file that I read using an XML Document object.

Path.Combine(m_appfolder, m_appname & ".config") defines that file which
holds a key/value pair that provides the path for the log file which is
completed with:

Path.Combine(ReadConfigSetting("<blah>", "exceptionfolder"),
"Exception.log")

This means that the log file is located where you want it.

There is a gotcha is that whatever account(s) the web service(s) run under
need to to have write permissions on the folder where you place the log
file(s).

"gregory_may" <None> wrote in message
news:OL*************@tk2msftngp13.phx.gbl...
Below is a routine I use for creating log files. It works great on most
VB Applications. However, for web services, it needs some help. The
problem is I cant reflect properly into a web service to find out where
the .DLL is. As is, this code writes a log file ok, but the log file ends
up buried directory deep inside the .Net Framework directories. Anyone
know how to find the path of a web service .DLL so I can fix this code to
write to the "bin" directory where the Web Service Dll is?
Public Function get_name_of_application(Optional ByVal
IncludeFullPathOfExe As Boolean = False) As String
Dim Application_Directory As String
Dim Asm As System.Reflection.Assembly = _
System.Reflection.Assembly.GetExecutingAssembly

Dim strConfigLoc As String = Asm.Location
If Not IncludeFullPathOfExe Then
strConfigLoc = GetFileNameOnly(Asm.Location)
End If

get_name_of_application = strConfigLoc.ToString
End Function

Public Sub COMMON_Module_Print(ByVal MyMessage As String, Optional
ByVal WriteToFile As Boolean = False)
Try
Static TodaysDate As Date = Now

Debug.WriteLine(MyMessage)

If WriteToFile Then
Dim OutputLogFileName As String =
get_name_of_application(True) & ".Log"
COMMON_FILE_Module.FILE_AppendFile(MyMessage,
OutputLogFileName)

If Now.Date < TodaysDate.Date Then
'Archive OutputFile
Dim ArchivedFileName As String = OutputLogFileName &
".Archived." & Now.Date.ToShortDateString.Replace("/", "-")
FILE_ForceMove(OutputLogFileName, ArchivedFileName)
TodaysDate = Now
End If

End If

Catch ex As Exception
RaiseEvent Mod_Print("COMMON_Module_Print: " & ex.Message)
End Try
End Sub

Nov 21 '05 #2

P: n/a
I wanted to make it "Automatic" in that I didn't want to hard code anything
from an XML file. My hope is I can find the path of the "REAL" .dll & put
the log file there.

"Stephany Young" <noone@localhost> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
This is how I do it:

Imports System.Web.Services
Imports System.IO
Imports System.Xml

<WebService(Namespace:="http://<blah.blah>/<blah>")> _
Public Class <blah>
Inherits WebService

Private m_appfolder As String
Private m_appname As String

Public Sub New()

MyBase.New()

InitializeComponent()

m_appname = Context.Request.ServerVariables.Item("path_transla ted")

m_appfolder = Path.GetDirectoryName(m_appname)

m_appname = Path.GetFileNameWithoutExtension(m_appname)

' Other code here

End Sub

' Other methods here

End Class

I then have a stock standard config file in the same directory as the
<blah>.asmx.vb file that I read using an XML Document object.

Path.Combine(m_appfolder, m_appname & ".config") defines that file which
holds a key/value pair that provides the path for the log file which is
completed with:

Path.Combine(ReadConfigSetting("<blah>", "exceptionfolder"),
"Exception.log")

This means that the log file is located where you want it.

There is a gotcha is that whatever account(s) the web service(s) run under
need to to have write permissions on the folder where you place the log
file(s).

"gregory_may" <None> wrote in message
news:OL*************@tk2msftngp13.phx.gbl...
Below is a routine I use for creating log files. It works great on most
VB Applications. However, for web services, it needs some help. The
problem is I cant reflect properly into a web service to find out where
the .DLL is. As is, this code writes a log file ok, but the log file ends
up buried directory deep inside the .Net Framework directories. Anyone
know how to find the path of a web service .DLL so I can fix this code to
write to the "bin" directory where the Web Service Dll is?
Public Function get_name_of_application(Optional ByVal
IncludeFullPathOfExe As Boolean = False) As String
Dim Application_Directory As String
Dim Asm As System.Reflection.Assembly = _
System.Reflection.Assembly.GetExecutingAssembly

Dim strConfigLoc As String = Asm.Location
If Not IncludeFullPathOfExe Then
strConfigLoc = GetFileNameOnly(Asm.Location)
End If

get_name_of_application = strConfigLoc.ToString
End Function

Public Sub COMMON_Module_Print(ByVal MyMessage As String, Optional
ByVal WriteToFile As Boolean = False)
Try
Static TodaysDate As Date = Now

Debug.WriteLine(MyMessage)

If WriteToFile Then
Dim OutputLogFileName As String =
get_name_of_application(True) & ".Log"
COMMON_FILE_Module.FILE_AppendFile(MyMessage,
OutputLogFileName)

If Now.Date < TodaysDate.Date Then
'Archive OutputFile
Dim ArchivedFileName As String = OutputLogFileName &
".Archived." & Now.Date.ToShortDateString.Replace("/", "-")
FILE_ForceMove(OutputLogFileName, ArchivedFileName)
TodaysDate = Now
End If

End If

Catch ex As Exception
RaiseEvent Mod_Print("COMMON_Module_Print: " & ex.Message)
End Try
End Sub


Nov 21 '05 #3

P: n/a
Gregory,

Than why don't you support that name to your function.

Just my thought,

Cor
Nov 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.