다음 보고서 서비스를 만들었지 만 EventLog에 아무 것도 기록 할 수 없습니다. 나는 창문 서비스 및 SUB 홈페이지로 시작 프로젝트로 응용 프로그램 유형을 설정 한 프로젝트 설정에서 ... 하나는 코드Windows 서비스에서 이벤트 로그에 쓸 수 없음
Program.vb
Imports System.ServiceProcess
Namespace ReportingService
Public Class Program
Private Sub New()
End Sub
''' <summary>The main entry point for the application.</summary>
Private Shared Sub Main(args As String())
Dim ServicesToRun As ServiceBase()
ServicesToRun = New ServiceBase() {
New ReportingImmediate()
}
ServiceBase.Run(ServicesToRun)
End Sub
End Class
End Namespace
ReportService.vb
에 무슨 잘못 제안시겠습니까Imports System.ServiceProcess
Imports System.Timers
Imports System.Configuration
Public Class ReportingImmediate
Inherits ServiceBase
#Region "Members"
Private ReadOnly time As Timer
Private ReadOnly rptHelper As ReportingHelper
Private ReadOnly timeInterval As String
#End Region
Public Sub New()
' Initialize Logs
InitializeComponent()
' Initialize other components
time = New Timer()
timeInterval = ConfigurationManager.AppSettings("ImmediateReRunInterval") '10000
time.Interval = Integer.Parse(timeInterval)
AddHandler time.Elapsed, AddressOf TimeElapsed
rptHelper = New ReportingHelper()
End Sub
#Region "Timer Event"
''' <summary>time Elapsed</summary>
''' <param name="sender">The object that raised the event sender</param>
''' <param name="e">Event data passed to the handler e</param>
Private Sub TimeElapsed(sender As Object, e As ElapsedEventArgs)
time.Enabled = False
rptHelper.WriteToEventLog("Logging Report Service")
' Enable the Timer
time.Enabled = True
time.Interval = Integer.Parse(timeInterval)
End Sub
#End Region
#Region "Service Events"
''' <summary>On Start</summary>
''' <param name="args">Arguments</param>
Protected Overrides Sub OnStart(args As String())
time.Enabled = True
End Sub
''' <summary>On Stop</summary>
Protected Overrides Sub OnStop()
time.Enabled = False
End Sub
#End Region
End Class
ReportHelper.vb 것은
Imports System.Data.OleDb
Imports System.Configuration
Imports System.Threading.Tasks
Imports System.IO
Imports System.IO.Packaging
Imports System.Text
Imports System.Net.Mail
Imports System.Net
Public Class ReportingHelper
Public Function WriteToEventLog(ByVal entry As String, Optional ByVal appName As String = "ReportingService", Optional ByVal eventType As _
EventLogEntryType = EventLogEntryType.Information, Optional ByVal logName As String = "RepotingServiceImmediate") As Boolean
Dim objEventLog As New EventLog
Try
'Register the Application as an Event Source
If Not EventLog.SourceExists(appName) Then
EventLog.CreateEventSource(appName, logName)
End If
'log the entry
objEventLog.Source = appName
objEventLog.WriteEntry(entry, eventType)
Return True
Catch Ex As Exception
Return False
End Try
End Function
End Class
서비스를 설치하려면 관리자 권한이 필요하므로 동시에 이벤트 소스를 만드는 것이 좋습니다. –
관리자 권한을 사용하여 서비스를 설치하고 있지만 이벤트 로그의 유일한 항목은 서비스가 성공적으로 시작되었고 성공적으로 중지되었으며 작성하지 않았습니다. ReportService.VB 파일의 새 이벤트와 타이머 이벤트를 직접 작성하려고 시도했지만 아무 일도 일어나지 않습니다. –
@NikhilGupta 기존 로그를 사용하십시오. 'logName = "Application"'을 사용하십시오. –