none
EventLog.WriteEntry RRS feed

  • Question

  • I'm not sure if anyone can help but I am having trouble writing to my own custom application event log.  This is being done via a CLR assembly.

    This is the code snippet ...

    Const strApp As String = "Custom App"

    <Microsoft.SqlServer.Server.SqlProcedure()> _
    Public Shared Function WriteToEventLog() As SqlInt32  
        
    ' If the source app doesn't exist, create it.
        
    If Not EventLog.SourceExists(strApp) Then
            EventLog.CreateEventSource(strApp, strApp)
        End If

        
    EventLog.WriteEntry(strApp, "This is a test", EventLogEntryType.Information)
    End Function

    It seems simple enough but I cannot find a way to get the entry to appear in the log.  I don't get any errors or anything else, the code simply runs through as normal but nothing appears in the event log.

    What am I doing wrong?!?

    Hopefully someone can help.

    Thanks

    Brad






    • Edited by Brad_302 Sunday, August 10, 2008 9:17 AM I had a line of code which was pointless.
    Sunday, August 10, 2008 9:16 AM

Answers

  • Well ... I have no idea why, but it's just decided to work.  That was only after I wrote something to the "Application" log.  Weird, it now works against the custom log I created.
    • Marked as answer by Zhi-Xin Ye Thursday, August 14, 2008 2:04 PM
    Monday, August 11, 2008 11:46 AM

All replies

  • The first parameter which you have specified as strApp is the Event source.

    See
    http://msdn.microsoft.com/en-us/library/hk2a9kek.aspx
    source
    Type: System..::.String

    The source by which the application is registered on the specified computer.


    Have you created this custom event source, using CreateEventSource function. If not, then you can use already created source such as "Application".

    --
    Madhur

    http://blogs.msdn.com/mahuja | Please mark the replies as answers if they help
    Monday, August 11, 2008 9:58 AM
  • Hi Madhur,

    Thanks for your reply.

    To answer your question, yes ... the both the event source and the log exist, they were created successfully without issue, hence why I can't understand why I am having this issue.

    I'm pretty stubborn with all of this and I really want my own application log rather than just rely on "Application" but I may not have a choice, I may have to resort to the default.

    I just tested the exact same code with the "Application" log and it works, not as smoothly as I would like but it works.

    Do you have anymore ideas?!?
    Monday, August 11, 2008 11:05 AM
  • Well ... I have no idea why, but it's just decided to work.  That was only after I wrote something to the "Application" log.  Weird, it now works against the custom log I created.
    • Marked as answer by Zhi-Xin Ye Thursday, August 14, 2008 2:04 PM
    Monday, August 11, 2008 11:46 AM
  • Great!!!
    http://blogs.msdn.com/mahuja | Please mark the replies as answers if they help
    Monday, August 11, 2008 11:48 AM