How does the user "log into the server"?
I think that you really have 2 separate applications here.
You could use precompiler statements to build 2 different applications based on the same code. One compiled version will be tailored to be installed and run on the server and the other version will be tailored to be installed and run locally.
So say you have a function in your code that logs errors. This function, when compiled for the server, will log an error message into the Windows Event Log. When this function is compiled for the local desktop client, error will be appended to a Log.txt file.
You would have the following code for the "LogError" subroutine:
-
Public Sub LogError(ByVal errorMessage As String)
-
#If APPLICATIONTYPE = "Server"
-
'Code that writes the error message to a
-
'Windows Event Log called "ServerApplicationLog"
-
-
Dim thelog As New System.Diagnostics.EventLog
-
Dim theSource As String = "ServerApplicationLog"
-
thelog.Source = theSource
-
'Recording the error
-
thelog.WriteEntry(errorMessage, Diagnostics.EventLogEntryType.Error)
-
thelog.Dispose()
-
#End If
-
-
#If APPLICATIONTYPE = "Local"
-
'Code that writes the error message to a TXT file
-
'called "clientLog.txt" that exists in the application's startup path.
-
-
Dim logFilePath As String = Application.StartupPath + "\clientLog.txt"
-
Using outfile As New StreamWriter(logFilePath)
-
outfile.Write(errorMessage)
-
End Using
-
#End If
-
End Sub
You would define the APPLICATIONTYPE variable by adding it the "Custom Constraints" in the Advanced Compiler Settings for your application.
To do this:
- Right click on your project name in the Solution Explorer and click Properties
- Click the Compiler tab/button
- Click the "Advanced Compile Options..." button
- In the Custom Constraints text box type: APPLICATIONTYPE = "ServerApplicationLog" if you are compiling the application for the server...otherwise type APPLICATIONTYPE = "Local"
- Click the Ok button
- Build your application
-Frinny