Hai
Am creating a web application using Vb.Net for data processing. I am
implementing multi threading in processing functions. And also i used
log4net to log the function calls and steps.
My application requires multiple log file. So i used the following code to
change the log files dynamically.
''' <summary>
''' Function used to set the name for Log File
''' </summary>
'''
'''
''' <remarks></remarks>
Public Shared Sub SetLogFileName(ByVal Jobid As String, ByVal jobtype As
String)
Try
Dim logFileName As String
If (Jobid = 0) Then
logFileName = HttpContext.Current.Server.MapPath("~/Log/Setup_Log.txt")
Else
logFileName = HttpContext.Current.Server.MapPath("~/Log/Job_" & jobtype &
"_" & Jobid & ".txt")
End If
ChangeLogFileName("LogFileAppender", logFileName)
Catch ex As Exception
Throw ex
End Try
End Sub
''' <summary>
''' Function used to change the Log File Name
''' </summary>
'''
''' New name for the file
''' <returns>Returns a Bool Value</returns>
'''
Public Shared Function ChangeLogFileName(ByVal AppenderName As String, ByVal
NewFilename As String) As Boolean
Try
XmlConfigurator.Configure()
Dim config As System.Configuration.Configuration =
System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~/")
Dim RootRep As log4net.Repository.ILoggerRepository
RootRep = log4net.LogManager.GetRepository()
For Each iApp As log4net.Appender.IAppender In RootRep.GetAppenders()
If iApp.Name.CompareTo(AppenderName) = 0 AndAlso TypeOf iApp Is
log4net.Appender.RollingFileAppender Then
Dim fApp As log4net.Appender.RollingFileAppender = DirectCast(iApp,
log4net.Appender.RollingFileAppender)
fApp.File = NewFilename
fApp.ActivateOptions()
' Appender found and name changed to NewFilename
Return True
End If
Next
' appender not found
Return False
Catch ex As Exception
Throw ex
End Try
End Function
Whan am trying to change the log files in side thread it shows object
reference issue in following line clsLoggerCheck.SetLogFileName(JobID,
"Analysis")
what is the reson for object reference? how can I solve this issue?
Thanks
--
View this message in context:
http://old.nabble.com/Object-Reference-issue-in-changing-the-Log-file-name-dynamically-in-threads-tp34508400p34508400.html
Sent from the Log4net - Dev mailing list archive at Nabble.com.