I have a wrapper I made for log4net, it has Debug, Info, Warn, Error, and
Fatal methods.
In my log.info it does not even take in an exception as it shouldn't being
an information.
The first DB insert works perfectly:
Id      Date       Thread       Level   AppId   Logger  Class   Method  Message 
Type    Exception
User
44      2011-07-12 14:54:53.470 10      INFO    TestApplication NULL    (null)  
(null)  Info
msg  (null)             meisenstein

However after an insert with a type and class and method (any Warn, Error,
Fatal) The next time log.Info("info msg") is called, it keeps the previous
information:

Id      Date    Thread  Level   AppId   Logger  Class   Method  Message Type    
Exception       User
48      2011-07-12 14:56:04.387 10      INFO    TestApplication NULL    Program 
Main    Info
msg     IndexOutOfRangeException                meisenstein

47      2011-07-12 14:55:24.977 10      FATAL   TestApplication NULL    Program 
Main    Fatal
msg     IndexOutOfRangeException        System.IndexOutOfRangeException: Index 
was
outside the bounds of the array.     at
CDS.Core.Logging.Program.Main(String[] args) in
C:\SourceControl\CDS.Core.Logging\TestProgram\Program.cs:line 21        
meisenstein

Notice how type was null before, but now it's IndexOutOfRangeException.

I have this method which sets these custom fields:
  private void SetExceptionDetail(string userId, Exception ex)
        {
            log4net.GlobalContext.Properties["appId"] = ApplicationName;

            if (userId != null)
                log4net.GlobalContext.Properties["user"] = userId;

            if (ex != null)
            {
                log4net.GlobalContext.Properties["type"] =
ex.GetType().Name;

                log4net.GlobalContext.Properties["method"] =
GetCallingMethodName();

                if (ex.TargetSite != null)
                {
                    if (ex.TargetSite.DeclaringType != null)
                        log4net.GlobalContext.Properties["class"] =
ex.TargetSite.DeclaringType.Name;
                }
            }
        }

But in info, the last 3 are skipped because ex is null

 public void Info(string message, string userName, params MailAddress[]
additionalRecipients)
        {
            if (LogLevel >= Level.Info)
            {
                try
                {
                    SetExceptionDetail(userName, null);

                    log4NetLogger.Info(message);
                }
                catch (Exception e)
                {
                    SendEmail(Level.Fatal, "Failed to log info event",
userName, e);
                }
            }
        }

any ideas on how to clear it to make sure that the previous stuff does not
get inserted when I call the info method?

-- 
View this message in context: 
http://old.nabble.com/Log4Net-Inserting-Wrong-Data-tp32048451p32048451.html
Sent from the Log4net - Users mailing list archive at Nabble.com.

Reply via email to