How to get log information with log4n

Jun 16, 2012 at 10:13 AM

Hello,

       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
{
    [ComVisible(true)]
    [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)
        {
            try
            {
                
                switch (control.Id)
                {
                    case "customButton1":
                        
                        //open Login Form
                        this.OpenLoginForm();
                        
                        break;
                    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";
                        
                        if(!File.Exists(userJson_path))
                        {
                            log4n.Info("user.json is not exists");
                            this.OpenLoginForm();
                        }
                        else if (String.IsNullOrEmpty(this.GetUser(userJson_path)) ||String.IsNullOrEmpty(this.GetPasswd(userJson_path)))
                        {
                            log4n.Info("username or password error.");
                            this.OpenLoginForm();
                        }
                        else 
                        {
                            // to do Sales2Outlook
                            olAddinMain.DoS2O();
                        }
                        
                                               break;
                    default:
                        MessageBox.Show("Unkown Control Id: " + control.Id);
                        break;
                }
            }
            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 -->
    <log4net>

        <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" />
            </layout>
        </appender>
        
        
        
        <!-- Setup the root category, add the appenders and set the default priority -->
        
        <root>
            <level value="info" />
            <appender-ref ref="RollingFileAppender" />
        </root>
    </log4net>