none
Unable to generate log by log4net

    Question

  • Hi All,

    In my biztalk project i have one helper library project which have one logger class and that logger class has reference for log4net. In my orchestration my using these methods from that class to generate log but i am unable to generate log.

    Steps which i had followed

    1) Created one biztalk project.
    2) Created one c# class library project - HelperLibrary(both in one solution)
    3) Biztalk project have reference to this helper library project
    4) HelperLibrary project have reference to Log4net.
    5) In SSO configuration created one key value which contains the details about the folder 

    SSO Config

    <log4net>
      <appender name=""RollingFileAppender"" type=""log4net.Appender.RollingFileAppender"">
        <file value=""E:\ABC\DEF\DebugLog\Debug.log"" />
        <appendToFile value=""true"" />
        <rollingStyle value=""Size"" />
        <maxSizeRollBackups value=""50"" />
        <maximumFileSize value=""2MB"" />
        <staticLogFileName value=""true"" />
        <layout type=""log4net.Layout.PatternLayout"">
          <conversionPattern value=""%date [%thread] %-5level %logger [%property{NDC}] - %message%newline"" />
        </layout>
      </appender>
      <appender name=""OutputDebugStringAppender"" type=""log4net.Appender.OutputDebugStringAppender"">
        <layout type=""log4net.Layout.PatternLayout"">
          <conversionPattern value=""%date [%thread] %-5level %logger [%property{NDC}] - %message%newline"" />
        </layout>
      </appender>
      <appender name=""UdpAppender"" type=""log4net.Appender.UdpAppender"">
        <param name=""RemoteAddress"" value=""127.0.0.1"" />
        <param name=""RemotePort"" value=""60606"" />
        <layout type=""log4net.Layout.PatternLayout"">
          <conversionPattern value=""%date [%thread] %-5level %logger [%property{NDC}] - %message%newline"" />
        </layout>
      </appender>
      <root>
        <level value=""ALL"" />
        <appender-ref ref=""OutputDebugStringAppender"" />
        <appender-ref ref=""UdpAppender"" />
      </root>
    </log4net>

    6) In orchestration calling the methods from logger file.

    But i am not able to generate the log.Please guide me on this issue.

    Thanxs

    Thursday, December 22, 2016 11:49 AM

Answers

  • Hey BD2016,

    Have following section in your Biztalk Config, You may need to change the version and Public key token based on your log4net DLL version.

    <configSections>
        <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,Log4net , Version=1.2.10.0, Culture=neutral, PublicKeyToken=1b44e1d426115821"/>    
      </configSections>

    and below section also in biztalk Config just before the <runtime> tag:

    <log4net configSource="log4net.xml"/>

    And create a new XML file in the SAME location (Eg. C:\Program Files (x86)\Microsoft BizTalk Server 2013) as of BTSConfig by the name 'log4net.xml' and place the log4net content there.

    <log4net>
      <appender name=""RollingFileAppender"" type=""log4net.Appender.RollingFileAppender"">
        <file value=""E:\ABC\DEF\DebugLog\Debug.log"" />
        <appendToFile value=""true"" />
        <rollingStyle value=""Size"" />
        <maxSizeRollBackups value=""50"" />
        <maximumFileSize value=""2MB"" />
        <staticLogFileName value=""true"" />
        <layout type=""log4net.Layout.PatternLayout"">
          <conversionPattern value=""%date [%thread] %-5level %logger [%property{NDC}] - %message%newline"" />
        </layout>
      </appender>
      <appender name=""OutputDebugStringAppender"" type=""log4net.Appender.OutputDebugStringAppender"">
        <layout type=""log4net.Layout.PatternLayout"">
          <conversionPattern value=""%date [%thread] %-5level %logger [%property{NDC}] - %message%newline"" />
        </layout>
      </appender>
      <appender name=""UdpAppender"" type=""log4net.Appender.UdpAppender"">
        <param name=""RemoteAddress"" value=""127.0.0.1"" />
        <param name=""RemotePort"" value=""60606"" />
        <layout type=""log4net.Layout.PatternLayout"">
          <conversionPattern value=""%date [%thread] %-5level %logger [%property{NDC}] - %message%newline"" />
        </layout>
      </appender>
      <root>
        <level value=""ALL"" />
        <appender-ref ref=""OutputDebugStringAppender"" />
        <appender-ref ref=""UdpAppender"" />
      </root>
    </log4net>

    Once done, DONT FORGET TO RESTART THE HOST INSTANCES and test.


    Rachit Sikroria (Microsoft Azure MVP)

    Thursday, December 22, 2016 2:53 PM
    Moderator

All replies

  • Hi BizTalkDeveloper2016,

    Do you get any errors in this ? any exceptions thrown during the call?

    Also have you tried setting up the file in the app.config instead of the SSO config?

    Please have a look at following thread may be this will help

    http://stackoverflow.com/questions/3618380/log4net-does-not-write-the-log-file

    Regards,


    Mandar Dharmadhikari

    Thursday, December 22, 2016 12:08 PM
    Moderator
  • Hi Mandar

    I dont get any error in this and i dont have any app.config in my biztalk solution

    Thursday, December 22, 2016 12:13 PM
  • Okk try in the btsntsvc.exe.config

    also have you called, as mentioned in the thread???

    log4net.Config.XmlConfigurator.Configure();


    Mandar Dharmadhikari

    Thursday, December 22, 2016 12:16 PM
    Moderator
  • yes i had called that in logger class

    private static readonly log4net.ILog log =
            log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

    so should i use  btsntsvc.exe.config in place of SSO config?

    Thursday, December 22, 2016 12:26 PM
  • The issue is suspect is that your log4net function is not able to read the config at all hence I am suggesting to put it in the btsntsvc.exe.config  and btsntsvc64.exe.configso that the we can check if that will resolve the issue

    Regards


    Mandar Dharmadhikari


    Thursday, December 22, 2016 12:28 PM
    Moderator
  • Hi Mandar

    this is my updated btsntsvc.config

    <?xml version="1.0" ?>
    <configuration>
        <startup useLegacyV2RuntimeActivationPolicy="true">
            <supportedRuntime version="v4.0" />
        </startup>
        <runtime>
            <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
                <probing privatePath="BizTalk Assemblies;Developer Tools;Tracking;Tracking\interop" />
            </assemblyBinding>
        </runtime>
        
    <log4net>
      <appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
        <file value="E:\ABC\DEF\DebugLog\Debug.log" />
        <appendToFile value="true" />
        <rollingStyle value="Size" />
        <maxSizeRollBackups value="50" />
        <maximumFileSize value="2MB" />
        <staticLogFileName value="true" />
        <layout type="log4net.Layout.PatternLayout">
          <conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
        </layout>
      </appender>
      <appender name="OutputDebugStringAppender" type="log4net.Appender.OutputDebugStringAppender" >
        <layout type="log4net.Layout.PatternLayout">
          <conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
        </layout>
      </appender>
      <appender name="UdpAppender" type="log4net.Appender.UdpAppender">
        <param name="RemoteAddress" value="127.0.0.1" />
        <param name="RemotePort" value="60606" />
        <layout type="log4net.Layout.PatternLayout">
          <conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
        </layout>
      </appender>
      <root>
        <level value="ALL" />
        <appender-ref ref="OutputDebugStringAppender" />
        <appender-ref ref="UdpAppender" />
      </root>
    </log4net>

        <system.runtime.remoting>
        
            <channelSinkProviders>
                <serverProviders>
                    <provider id="sspi" type="Microsoft.BizTalk.XLANGs.BTXEngine.SecurityServerChannelSinkProvider,Microsoft.XLANGs.BizTalk.Engine" securityPackage="ntlm" authenticationLevel="packetPrivacy" />
                </serverProviders>
            </channelSinkProviders>
        
            <application>
                <channels>
                    <channel ref="tcp" port="0" name="">
                   <serverProviders>
                       <provider ref="sspi" />
                            <formatter ref="binary" typeFilterLevel="Full"/>
                        </serverProviders>
                    </channel>
                </channels>
            </application>
        </system.runtime.remoting>

        
    </configuration>

    and i am get this error in application log:

    A failure occurred when executing a Windows service request.
     
     Service request: Start 
     
     BizTalk host name: Quote
     Windows service name: BTSSvc$Quote 
     
     Additional error information:
     Error code: 0x80131604
     Error source: mscorlib
     Error description: Exception has been thrown by the target of an invocation. 


    Thursday, December 22, 2016 12:48 PM
  • Hi BiztalkDeveloper2016.

    Add following code inside the <Configuration> </Configuration> just before the <Log4Net> section to the btsntsvc.exe.config file, your log4net section is not getting recognized hence it is messing up the btsntsvc.exe.config

    <configSections>
    
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
    
    </configSections>
    

    Your btsntsvc.exe.config file should look like below

    <configuration>
         <startup useLegacyV2RuntimeActivationPolicy="true">
             <supportedRuntime version="v4.0" />
         </startup>
         <runtime>
             <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
                 <probing privatePath="BizTalk Assemblies;Developer Tools;Tracking;Tracking\interop" />
             </assemblyBinding>
         </runtime>
         <configSections>
    
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
    
    </configSections>
    
    <log4net>
       <appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
         <file value="E:\ABC\DEF\DebugLog\Debug.log" />
         <appendToFile value="true" />
         <rollingStyle value="Size" />
         <maxSizeRollBackups value="50" />
         <maximumFileSize value="2MB" />
         <staticLogFileName value="true" />
         <layout type="log4net.Layout.PatternLayout">
           <conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
         </layout>
       </appender>
       <appender name="OutputDebugStringAppender" type="log4net.Appender.OutputDebugStringAppender" >
         <layout type="log4net.Layout.PatternLayout">
           <conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
         </layout>
       </appender>
       <appender name="UdpAppender" type="log4net.Appender.UdpAppender">
         <param name="RemoteAddress" value="127.0.0.1" />
         <param name="RemotePort" value="60606" />
         <layout type="log4net.Layout.PatternLayout">
           <conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
         </layout>
       </appender>
       <root>
         <level value="ALL" />
         <appender-ref ref="OutputDebugStringAppender" />
         <appender-ref ref="UdpAppender" />
       </root>
     </log4net>
    
         <system.runtime.remoting>
         
             <channelSinkProviders>
                 <serverProviders>
                     <provider id="sspi" type="Microsoft.BizTalk.XLANGs.BTXEngine.SecurityServerChannelSinkProvider,Microsoft.XLANGs.BizTalk.Engine" securityPackage="ntlm" authenticationLevel="packetPrivacy" />
                 </serverProviders>
             </channelSinkProviders>
         
             <application>
                 <channels>
                     <channel ref="tcp" port="0" name="">
                   <serverProviders>
                       <provider ref="sspi" />
                             <formatter ref="binary" typeFilterLevel="Full"/>
                         </serverProviders>
                     </channel>
                 </channels>
             </application>
         </system.runtime.remoting>
    
         
     </configuration>

    Regards,


    Mandar Dharmadhikari

    Thursday, December 22, 2016 1:06 PM
    Moderator
  • still same issue...:(
    Thursday, December 22, 2016 1:18 PM
  • Thursday, December 22, 2016 1:29 PM
    Moderator
  • Hey BD2016,

    Have following section in your Biztalk Config, You may need to change the version and Public key token based on your log4net DLL version.

    <configSections>
        <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,Log4net , Version=1.2.10.0, Culture=neutral, PublicKeyToken=1b44e1d426115821"/>    
      </configSections>

    and below section also in biztalk Config just before the <runtime> tag:

    <log4net configSource="log4net.xml"/>

    And create a new XML file in the SAME location (Eg. C:\Program Files (x86)\Microsoft BizTalk Server 2013) as of BTSConfig by the name 'log4net.xml' and place the log4net content there.

    <log4net>
      <appender name=""RollingFileAppender"" type=""log4net.Appender.RollingFileAppender"">
        <file value=""E:\ABC\DEF\DebugLog\Debug.log"" />
        <appendToFile value=""true"" />
        <rollingStyle value=""Size"" />
        <maxSizeRollBackups value=""50"" />
        <maximumFileSize value=""2MB"" />
        <staticLogFileName value=""true"" />
        <layout type=""log4net.Layout.PatternLayout"">
          <conversionPattern value=""%date [%thread] %-5level %logger [%property{NDC}] - %message%newline"" />
        </layout>
      </appender>
      <appender name=""OutputDebugStringAppender"" type=""log4net.Appender.OutputDebugStringAppender"">
        <layout type=""log4net.Layout.PatternLayout"">
          <conversionPattern value=""%date [%thread] %-5level %logger [%property{NDC}] - %message%newline"" />
        </layout>
      </appender>
      <appender name=""UdpAppender"" type=""log4net.Appender.UdpAppender"">
        <param name=""RemoteAddress"" value=""127.0.0.1"" />
        <param name=""RemotePort"" value=""60606"" />
        <layout type=""log4net.Layout.PatternLayout"">
          <conversionPattern value=""%date [%thread] %-5level %logger [%property{NDC}] - %message%newline"" />
        </layout>
      </appender>
      <root>
        <level value=""ALL"" />
        <appender-ref ref=""OutputDebugStringAppender"" />
        <appender-ref ref=""UdpAppender"" />
      </root>
    </log4net>

    Once done, DONT FORGET TO RESTART THE HOST INSTANCES and test.


    Rachit Sikroria (Microsoft Azure MVP)

    Thursday, December 22, 2016 2:53 PM
    Moderator
  • Do you really have to use log4Net?  It would be much easier to just eliminate it.

    Really, you won't be losing much if anything.

    Thursday, December 22, 2016 2:56 PM
    Moderator
  • Hi Johns-305

    Yes i have to use log4net.

    Friday, December 23, 2016 5:33 AM
  • hi Rachit

    i tried the way you had suggested but i am facing one issue. when i try to restart the host instance it gives me the following error

    Error:

       

    A failure occurred when executing a Windows service request.

     Service request: Start 

     BizTalk host name: BizTalkServerApplication
     Windows service name: BTSSvc$BizTalkServerApplication 

     Additional error information:
     Error code: 0x80131604
     Error source: mscorlib
     Error description: Exception has been thrown by the target of an invocation. 

    Changes made in Config: 

    <?xml version="1.0" ?>
    <configuration>
        <startup useLegacyV2RuntimeActivationPolicy="true">
            <supportedRuntime version="v4.0" />
        </startup>
          <log4net configSource="log4net.xml"/>
    <configSections>
        <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,Log4net , Version=1.2.15.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a"/>    
      </configSections>

        <runtime>
            <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
                <probing privatePath="BizTalk Assemblies;Developer Tools;Tracking;Tracking\interop" />
            </assemblyBinding>
        </runtime>
        <system.runtime.remoting>
            <channelSinkProviders>
                <serverProviders>
                    <provider id="sspi" type="Microsoft.BizTalk.XLANGs.BTXEngine.SecurityServerChannelSinkProvider,Microsoft.XLANGs.BizTalk.Engine" securityPackage="ntlm" authenticationLevel="packetPrivacy" />
                </serverProviders>
            </channelSinkProviders>
            <application>
                <channels>
                    <channel ref="tcp" port="0" name="">
                   <serverProviders>
                       <provider ref="sspi" />
                            <formatter ref="binary" typeFilterLevel="Full"/>
                        </serverProviders>
                    </channel>
                </channels>
            </application>
        </system.runtime.remoting>
    </configuration>

    Friday, December 23, 2016 6:10 AM
  • Hi Rachit

    That host instance is restarted now but that logger issue is still there. I am not able to generate the log.

    Friday, December 23, 2016 6:57 AM
  • Thanxs Rachit that worked for me...i cleaned all the code and started from scratch. It works 
    Monday, December 26, 2016 5:33 AM