473,466 Members | 1,639 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Creating A log File for Web Services?

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
3 4885
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
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
Gregory,

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

Just my thought,

Cor
Nov 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: tim.tadh | last post by:
Hi I am writing a program that allows a user to annotate text documents, and later html, html variants, and PDF files. My program is able to load multiple documents at once and creat linked...
7
by: Jan Danielsson | last post by:
Hello all, Is there any way to create a file with a specified size?
7
by: Selden McCabe | last post by:
I'm using the following code to write some text to a file: objWriter = New StreamWriter(FullPath, True, System.Text.Encoding.ASCII) For nRow = 1 To sData.Length - 1...
0
by: reidarT | last post by:
Ugyldig på toppnivået av dokumentet. Feil under behandling av ressursen file:///C:/VB/WebBrowser/WebBrowserControl/TESTFILE... "<?xml version=""1.0""?>","<XMLTest>" ^FileOpen(1,...
1
by: ReidarT | last post by:
The former post was wrong, the lines where concatenated so here it goes again. I am wrriting to a file (XML-format) and using FileOpen(1, "C:\vb\WebBrowser\WebBrowserControl\TESTFILE.XML",...
2
by: Amongin Ewinyu | last post by:
Hi, I'm trying to create a Windows service programmatically that will do the following: - When a user logs on, it will automatically run a service that uses BITS (Background Intelligent...
1
by: Dror Hershkovitz. | last post by:
Hello, I'm compiling an .exe file on VS2005 under C++ without framework support. For some reason, when I look at the properties of the .exe file there is no version tab although the project does...
4
by: joerozario | last post by:
In .net 2005 I have created Application I want to create a log file, which maintains all the internal process so at the run time I want to create a file at the source Code: Private string...
4
by: Dica | last post by:
we just ordered VS 2005 standard edition. i was reading up on creating windows services and apparently this is only possible with the enterprise edition. is this true, or does it simply mean...
3
by: XDeveloper | last post by:
Hi Dear Fellows! I recently have passed Java! And I choose C++ way! So and now I need to understand how can I built below problem! With a binary file operations of addition, removal and...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.