Hi anil, I have the impression you know by now what needs to be changed to make it work for parallel invocations. Would you be willing to write, test and propose a fix as a pull request? You should also add some unit tests that prove that the codebase still works as expected when not invoking from parallel calls, fails in parallel calls without the patch and succeeds in parallel calls with the patch.
Cheers, Dominik On Tue, 10 Jan 2023 at 09:16, anil <anil....@gmail.com> wrote: > Hi dominik, > > In EventLogAppender The below code is not able to handle the parallel > calls. the highlighted code is failing when we are invoking the same method > using Parallel.Invoke method > > override public void ActivateOptions() > { > base.ActivateOptions(); > > if (m_securityContext == null) > { > m_securityContext = > SecurityContextProvider.DefaultProvider.CreateSecurityContext(this); > } > > bool sourceAlreadyExists = false; > string currentLogName = null; > > using(SecurityContext.Impersonate(this)) > { > sourceAlreadyExists = EventLog.SourceExists(m_applicationName); > if (sourceAlreadyExists) > { > currentLogName = EventLog.LogNameFromSourceName(m_applicationName, > m_machineName); > } > } > > if (sourceAlreadyExists && currentLogName != m_logName) > { > LogLog.Debug("EventLogAppender: Changing event source [" + > m_applicationName + "] from log [" + currentLogName + "] to log [" + > m_logName + "]"); > } > else if (!sourceAlreadyExists) > { > LogLog.Debug("EventLogAppender: Creating event source Source [" + > m_applicationName + "] in log " + m_logName + "]"); > } > > string registeredLogName = null; > > using(SecurityContext.Impersonate(this)) > { > if (sourceAlreadyExists && currentLogName != m_logName) > { > // > // Re-register this to the current application if the user has changed > // the application / logfile association > // > EventLog.DeleteEventSource(m_applicationName, m_machineName); > CreateEventSource(m_applicationName, m_logName, m_machineName); > > registeredLogName = EventLog.LogNameFromSourceName(m_applicationName, > m_machineName); > } > > > * else if (!sourceAlreadyExists) { CreateEventSource(m_applicationName, > m_logName, m_machineName);* > > registeredLogName = EventLog.LogNameFromSourceName(m_applicationName, > m_machineName); > } > } > > m_levelMapping.ActivateOptions(); > > LogLog.Debug("EventLogAppender: Source [" + m_applicationName + "] is > registered to log [" + registeredLogName + "]"); > } > > On Tue, Jan 10, 2023 at 1:13 PM Dominik Psenner <dpsen...@gmail.com> > wrote: > >> Hi Anil, >> >> without a stack trace the best I can provide is an educated guess. To me >> it looks suspicious that the exception message reads "Source >> *Log4NetTest.exe* already exists on the local computer.". I would start >> investigating why the executable name is in the exception message and why >> the application confirms with an exception that the executable exists on >> the local computer. >> >> Warm regards, >> Dominik >> >> On Tue, 10 Jan 2023 at 04:41, anil <anil....@gmail.com> wrote: >> >>> >>> >>> >>> >>> Hi Team, >>> >>> This is Anil. I am working as a .net Tech Lead and i am using log4net >>> for logging purposes. >>> >>> Below are the version details of the same >>> >>> [image: image.png] >>> >>> >>> I am trying to execute the Parllel.Invoke which intiializes the EventLog >>> Appender as below and calls the ActivateOptions method >>> >>> System.Threading.Tasks.Parallel.Invoke(() => CreateEventLogger(), >>> () => CreateEventLogger(), () => CreateEventLogger()); >>> >>> >>> >>> private void CreateEventLogger() >>> { >>> var eventLogger = new EventLogAppender(); >>> eventLogger.ActivateOptions(); >>> } >>> >>> I am getting the below error for the first time where the event source >>> is not created. >>> >>> *Source Log4NetTest.exe already exists on the local computer.* >>> Document >>> NameValueType >>> ◢ $exception {"Source Log4NetTest.exe already exists on the local >>> computer."} System.ArgumentException >>> we are creating multiple hpc tasks in the HPC job manager which is using >>> log4net for logging. >>> >>> Can you please let us know if there is any fix for this issue? >>> >>> Regards, >>> >>> Anil >>> >> >> >> -- >> Dominik Psenner >> > -- Dominik Psenner