vb.net arcgis add in, log4net does not work by installing esriAddIn

1268
3
06-23-2014 10:53 PM
LiYao
by
New Contributor III
Hi everybody,

I want to use log4net in my vb.net for ArcGIS add-in. After I build the solution, it generates a .exe file and a .esriAddIn file.
The problem is when I run the .exe file (without open ArcMap), the log4net works, but when I install the .esriAddIn in ArcMap, and call a form from ArcMap, the log4net doesn't work at all.

I check from internet but most of the answers are talking about c#.net, this problem call me crazy, anybody has the experience of using log4net in vb.net ArcGIS add in?

Any help will be appreciated. thanks.
0 Kudos
3 Replies
RobertMaddox
New Contributor III
Well first off, if your project is compiling an exe file when you build your addin, then you have your build settings wrong. It should be compiling to a dll file, which is then included in the esriaddin file. Next, take the generated esriaddin file and change its extension to zip. Then look in that zip file and go to the Install folder and make sure that the log4net dll and xml files are there. If that's all good, take a look at the code that I have for a vb.net addin that uses log4net.

'This is the function I call when I need to get the ILog object for logging
Dim m_blnLogConfigured As Boolean
Public Function GetConfiguredLog(ByVal LoggerName As System.Type) As log4net.ILog
    If Not m_blnLogConfigured Then
        m_blnLogConfigured = True
        log4net.Util.LogLog.InternalDebugging = System.Diagnostics.Debugger.IsAttached
        Dim AssemblyLocation As String = System.Reflection.Assembly.GetExecutingAssembly.Location
        Dim ConfigFilePath As String = IO.Path.Combine(IO.Path.GetDirectoryName(AssemblyLocation), "log4net.xml")
        log4net.Config.XmlConfigurator.Configure(New IO.FileInfo(ConfigFilePath))
    End If
    Return log4net.LogManager.GetLogger(LoggerName)
End Function


[HTML]
<!-- This is the log4net.xml file that configures it for my addin -->
<?xml version="1.0" encoding="utf-8" ?>
<log4net>
  <appender name="RollingFile" type="log4net.Appender.RollingFileAppender">
    <file value="MyApplicationLog.log" />
    <appendToFile value="true" />
    <maximumFileSize value="1024KB" />
    <maxSizeRollBackups value="10" />
    <layout type="log4net.Layout.PatternLayout">
      <conversionPattern value="%date %level %logger - %message%newline" />
    </layout>
  </appender>
  <root>
    <level value="ALL" />
    <appender-ref ref="RollingFile" />
  </root>
</log4net>
[/HTML]

And I can confirm that this works without a problem. It creates the log file in C:\Program Files (x86)\ArcGIS\Desktop10.1\bin\MyApplicationLog.log, which may be a problem if you aren't running ArcMap as an administrator. I'll have to check and see if there's a way to tell it to put it somewhere else.

NOTE: I just looked at the version I have (1.2.10) and the release notes (http://logging.apache.org/log4net/release/release-notes.html) and found that there appear to have been some significant changes since the version that I've been using. So keep that in mind. I'm going to add it to my todo list for this project to look into updating log4net. If I find that there are significant changes that need to be made, I'll post back here to let everyone know. 😉
0 Kudos
LiYao
by
New Contributor III
Hi robby,

Thank you very much for your detailed answer. I have successfully set the build to dll instead of exe and check the requirements you mentioned. But I still cannot get the log4net work. I am using log4net 1.2.10 and follow the link here : http://www.codeproject.com/Articles/42276/How-to-Use-Log-Net-with-VB-NET-A-Simple-Step-By-St

Regards
0 Kudos
LiYao
by
New Contributor III
Hi Robby,

Finally make it work. What I do is modifying the AssemblyInfo.vb, and hard code the setting of log4net.Config.XMLConfigurator (configFile). Later I will try to find a proper way to set it (instead of hard coding).

Thanks for your help.
0 Kudos