Click here to Skip to main content
15,886,919 members
Home / Discussions / .NET (Core and Framework)
   

.NET (Core and Framework)

 
GeneralRe: accessing data from a table with a relationship Pin
hermitbluedog10-Dec-04 22:29
hermitbluedog10-Dec-04 22:29 
GeneralThreads and Appdomains Pin
F.D.I26-Nov-04 3:45
F.D.I26-Nov-04 3:45 
GeneralExtracting a digital certificate from a file. Pin
sillypuppy26-Nov-04 0:01
sillypuppy26-Nov-04 0:01 
General.net datagrid column editing Pin
sxsunda25-Nov-04 19:06
susssxsunda25-Nov-04 19:06 
GeneralRequested Registry Access is Not Allowed Pin
KreativeKai24-Nov-04 9:07
professionalKreativeKai24-Nov-04 9:07 
GeneralRe: Requested Registry Access is Not Allowed Pin
The Man from U.N.C.L.E.2-Dec-04 1:46
The Man from U.N.C.L.E.2-Dec-04 1:46 
GeneralRe: Requested Registry Access is Not Allowed Pin
KreativeKai2-Dec-04 2:40
professionalKreativeKai2-Dec-04 2:40 
GeneralRe: Requested Registry Access is Not Allowed Pin
The Man from U.N.C.L.E.2-Dec-04 3:13
The Man from U.N.C.L.E.2-Dec-04 3:13 
Here is the code we use in VB.Net (at least the Event log bit of it). If you prefer C# let me know and I'll post a C# version.

Imports System.Security
Imports System.Threading
Imports System.Environment
Imports System.Security.Permissions

Public Class EventLogService

    '''-----------------------------------------------------------------------------
    ''' <summary>
    '''      Error message to be thrown if access is denied.
    ''' </summary>
    '''-----------------------------------------------------------------------------
    Private Const EVENTLOG_DENIED As String = "The event source {0} does not exist and cannot be created with the current permissions."

    '''-----------------------------------------------------------------------------
    ''' <summary>
    '''     Publicly exposed method to create event log entries.
    ''' </summary>
    ''' <param name="text">The text of the log to create.</param>
    ''' <remarks>
    '''     This attempts to create an entry in the WestwoodForster event log
    '''     using the current AppDomain Friendly name as the event source name.
    '''     If this cannot be done for any reason then the entry will be created
    '''     as an 'Application Error' in the Application event log.
    '''     Additionaly a check is performed so that is event logging is not supported,
    '''     such as on Windows 98, no action is performed.
    ''' </remarks>
    ''' <history>
    ''' 	[mjackson] 	19/07/2004	Created
    ''' </history>
    '''-----------------------------------------------------------------------------
    Public Sub CreateEntry(ByVal text As String)

        Dim eventlogPermission As New System.Diagnostics.EventLogPermission(PermissionState.Unrestricted)
        eventlogPermission.Assert()

        Try
            Me.writeEventLogEntry(text)
        Catch ex As PlatformNotSupportedException
        End Try

        eventlogPermission.RevertAssert()

    End Sub

    '''-----------------------------------------------------------------------------
    ''' <summary>
    '''     Internal method to write to event log.
    ''' </summary>
    ''' <param name="text">Message to log.</param>
    ''' <remarks></remarks>
    ''' <history>
    ''' 	[mjackson] 	19/07/2004	Created
    ''' </history>
    '''-----------------------------------------------------------------------------
    Private Sub writeEventLogEntry(ByVal text As String)

        Dim eventsource As String
        eventsource = AppDomain.CurrentDomain.FriendlyName

        Me.validateEventSource(eventsource)

        Try
            EventLog.WriteEntry(eventsource, text, EventLogEntryType.Error, 1000)
        Catch e As SecurityException
            Throw New SecurityException(String.Format(EVENTLOG_DENIED, AppDomain.CurrentDomain.FriendlyName), e)
        End Try

    End Sub

    '''-----------------------------------------------------------------------------
    ''' <summary>
    '''     Internal method to validate or create event sources.
    ''' </summary>
    ''' <param name="eventSource">The name of the event source to create.</param>
    ''' <remarks>
    '''     Defaults to 'Application error' if could not be created.
    ''' </remarks>
    ''' <history>
    ''' 	[mjackson] 	19/07/2004	Created
    ''' </history>
    '''-----------------------------------------------------------------------------
    Private Sub validateEventSource(ByRef eventSource As String)

        Try
            If Not EventLog.SourceExists(eventSource) Then
                EventLog.CreateEventSource(eventSource, "CustomEventLog")
            End If
        Catch e As SecurityException
            eventSource = "Application Error"
        End Try

    End Sub

End Class


If you have knowledge, let others light their candles at it.
Margaret Fuller (1810 - 1850)
GeneralRe: Requested Registry Access is Not Allowed Pin
The Man from U.N.C.L.E.2-Dec-04 22:37
The Man from U.N.C.L.E.2-Dec-04 22:37 
GeneralRe: Requested Registry Access is Not Allowed Pin
The Man from U.N.C.L.E.2-Dec-04 23:47
The Man from U.N.C.L.E.2-Dec-04 23:47 
GeneralRe: Requested Registry Access is Not Allowed Pin
KreativeKai9-Dec-04 8:09
professionalKreativeKai9-Dec-04 8:09 
GeneralOleDbDataReader + Excel Pin
dvd0024-Nov-04 4:49
dvd0024-Nov-04 4:49 
QuestionGlobal CBT in .NET? Pin
Hadi Fakhreddine23-Nov-04 22:57
Hadi Fakhreddine23-Nov-04 22:57 
GeneralChanging URI's dynamically for web service clients Pin
burrifro7923-Nov-04 15:36
burrifro7923-Nov-04 15:36 
GeneralLotus NOtes Pin
rogerruiz23-Nov-04 10:01
rogerruiz23-Nov-04 10:01 
GeneralRe: Lotus NOtes Pin
Kevin McFarlane26-Nov-04 5:07
Kevin McFarlane26-Nov-04 5:07 
GeneralRe: Lotus NOtes Pin
rogerruiz26-Nov-04 7:39
rogerruiz26-Nov-04 7:39 
GeneralRe: Lotus NOtes Pin
Kevin McFarlane26-Nov-04 8:44
Kevin McFarlane26-Nov-04 8:44 
GeneralRe: Lotus NOtes Pin
rogerruiz26-Nov-04 8:47
rogerruiz26-Nov-04 8:47 
GeneralRe: Lotus NOtes Pin
Kevin McFarlane26-Nov-04 10:44
Kevin McFarlane26-Nov-04 10:44 
GeneralMicrosoft 2003 Toolkit Pin
sweep12322-Nov-04 5:59
sweep12322-Nov-04 5:59 
QuestionHow to manage two apps Pin
Jack_pt21-Nov-04 1:50
Jack_pt21-Nov-04 1:50 
AnswerRe: How to manage two apps Pin
DavidNohejl21-Nov-04 4:27
DavidNohejl21-Nov-04 4:27 
GeneralRe: How to manage two apps Pin
Jack_pt21-Nov-04 15:53
Jack_pt21-Nov-04 15:53 
GeneralRe: How to manage two apps Pin
Anonymous21-Nov-04 17:59
Anonymous21-Nov-04 17:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.