Friday, May 15, 2009

Write to System Log in Vb.net

To write an entry to System Log, you could do it 2 ways:
  1. Use existing source "Application" in the Event Viewer
  2. Create new source just for your application
BTW: To write logs, all functions are defined under System.Diagnositcs.EventLog namespace. Use: Imports System.Diagnostics.EventLog
To write to existing source, use:
EventLog.WriteEntry("TestApp", "This is Test") -- This will write log under Application with source name as TestApp.
To write to new source, use:
Dim objEventLog As New System.Diagnostics.EventLog()
Dim AppName As String = "Test App"
Dim LogName As String = "My Log"

'Register the App as an Event Source
If Not System.Diagnostics.EventLog.SourceExists(AppName) Then
       System.Diagnostics.EventLog.CreateEventSource(AppName, LogName)
End If
objEventLog.Source = LogName
objEventLog.WriteEntry("This is Test")

HTH.

Sunday, May 10, 2009

SqlServer 2000 Error Logging

To log error in sql log / windows log, just exec the following SP:

….sql code goes here which will cause error.
--To check for error, we use @@error global variable predefined in sql.
set @error = @@error
if @error <> 0
exec sp_altermessage @error ,'with_log', 'true'

To view the error, you can either view either in
  1. windows event viewer
  2. SQL server Mgmt studio , path is : --> Management --> Sql Server Logs
  3. exec master..xp_readerrorlog
To learn more visit
http://www.sqlservercentral.com/articles/Error+Description/65013/

Regards

Saturday, April 25, 2009

MSMQ 4.0 Queue name with .svc

In MSMQ 4.0, if you have a queue name with .svc at the end, you may need to do some additional steps to deliver your messages to receiver over http.

Fix:
  1. Uninstall your WCF components and MSMQ HTTP feature.
  2. Install MSMQ http feature first
  3. Then Install WCF components

This is bug in MSMQ 4.0 and is well explained in the following kb article.

http://support.microsoft.com/default.aspx?scid=kb;EN-US;936502

Basically if you install WCF components before Message Queuing HTTP Support feature (or even together), then the handler mappings are created for the request path whose name contains ".svc" when you enable the WCF feature. The handler mappings are in the Internet Information Services (IIS) default Web site. When you enable the Message Queuing HTTP Support feature, the handler mappings are copied to the Message Queuing virtual directory. This behavior occurs before the Message Queuing HTTP handler mappings are created for the Message Queuing virtual directory. Therefore, any Message Queuing HTTP request to a queue whose name contains ".svc" is sent to the WCF handlers instead of to the Message Queuing HTTP handlers.

Hope this helps.

Saqib