This project has moved and is read-only. For the latest updates, please go here.

How to get log information with log4n

Jun 16, 2012 at 10:13 AM


       I have donw a outlook2010 Addin program ,i want to get some log information with log4n,but i cat not get any trace information.

    MessageBox.Show("This is customButton2");

// MessageBox  right.
log4n.Info("This is customButton2");

// there is no file e:\SalesOutlook.Addin.log" 

MessageBox.Show("This is customButton2 END.");

// MessageBox right .

      Followint is my code ,pls help me.

using log4net;
using log4net.Config;

[assembly: log4net.Config.Repository("OutlookRibbonAddinCSharp")]
[assembly: log4net.Config.XmlConfigurator(ConfigFileExtension="log4n",Watch=true)]

namespace OutlookAddin
    [GuidAttribute("37AED73E-B93D-4a86-A021-DC19BE4782E3"), ProgId("SalesOutlook.Addin")]
    public class OutlookRibbonAddin : IDTExtensibility2, Office.IRibbonExtensibility
        private static readonly string _addinRegistryKey = "Software\\Microsoft\\Office\\Outlook\\AddIns\\";
        private static readonly string _prodId           = "SalesOutlook.Addin";
        private static readonly string _addinName        = "SalesOutlook";

   // .....

    #region Ribbon Gui Trigger
        public static ILog log4n = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);



public void OnAction(Office.IRibbonControl control)
                switch (control.Id)
                    case "customButton1":
                        //open Login Form
                    case "customButton2":
                        //check login username/passwd

                        MessageBox.Show("This is customButton2");
                        log4n.Info("This is customButton2");
                        MessageBox.Show("This is customButton2 END.");

                        string currentpath =  System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
                        string userJson_path = currentpath+"\\file\\user.json";
                            log4n.Info("user.json is not exists");
                        else if (String.IsNullOrEmpty(this.GetUser(userJson_path)) ||String.IsNullOrEmpty(this.GetPasswd(userJson_path)))
                            log4n.Info("username or password error.");
                            // to do Sales2Outlook
                        MessageBox.Show("Unkown Control Id: " + control.Id);
            catch (Exception throwedException)
                string details = string.Format("{1}{1}Details:{1}{1}{0}", throwedException.Message, Environment.NewLine);
                MessageBox.Show("An error occured in OnAction." + details, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);


Following is the OutlookRibbonAddinCSharp.dll.log4n file

<?xml version="1.0" encoding="utf-8" ?>
<!-- This section contains the log4net configuration settings -->

        <appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
            <!--<file value="${TMP}\SalesOutlook.Addin.log" />-->
            <file value="e:\SalesOutlook.Addin.log" />
            <appendToFile value="true" />
            <rollingStyle value="Size" />
            <maxSizeRollBackups value="10" />
            <maximumFileSize value="2000KB" />
            <staticLogFileName value="true" />
            <layout type="log4net.Layout.PatternLayout">
                <conversionPattern value="%date [%-5level] [%logger:%line] - %message%newline" />
        <!-- Setup the root category, add the appenders and set the default priority -->
            <level value="info" />
            <appender-ref ref="RollingFileAppender" />