Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > .NET General

Vista - log4net: Custom appender not being invoked

Reply
 
Old 02-22-2009   #1 (permalink)
rh.krish


 
 

log4net: Custom appender not being invoked

I have written a custom appender to output log messages to Paul Bunyan
Service. (Paul Bunyan is a log viewer and a service from www.diamondsierra.com).
The problem that I have is I'm seeing the logs in Paul Bunyan viewer
in every environment (DEV, TEST, STAGING), except the PROD box. I
don't see any sign of loading this dll. Here is my code:

public class Log4netPaulBunyanAppender : AppenderSkeleton
{
private static ILog log = LogManager.GetLogger
(MethodBase.GetCurrentMethod().DeclaringType);
protected override void Append(log4net.Core.LoggingEvent
loggingEvent)
{
try
{
string context = null;
ThreadContextStack property =
loggingEvent.LookupProperty("NDC") as ThreadContextStack;
if ((property != null) && (property.Count > 0))
context = property.ToString();
string loggerName = loggingEvent.LoggerName;
string renderedMessage = null;
if (this.Layout == null)
renderedMessage = loggingEvent.RenderedMessage;
else
renderedMessage = base.RenderLoggingEvent
(loggingEvent);
if (context == null)
context = string.Empty;
string instanceId = loggingEvent.Properties
["InstanceId"] as string;
if (instanceId != null)
context = string.Format(format, context,
instanceId);
string pbContext = loggingEvent.Properties
["pbcontext"] as string;
if (pbContext != null)
context = string.Format(format, context,
pbContext);
string exceptionString =
loggingEvent.GetExceptionString();
if ((exceptionString != null) &&
(exceptionString.Length > 0))
renderedMessage = string.Format(format,
renderedMessage, exceptionString);
LocationInfo locInfo = null;
int lineNumber = 0;
string fileName = string.Empty;
locInfo = loggingEvent.LocationInformation;
bool isNumber = int.TryParse(locInfo.LineNumber, out
lineNumber);
fileName = locInfo.FileName;
// Log the event.
PBUtil.Log(fileName, ((isNumber) ? (UInt32)
lineNumber : (UInt32)0), loggerName, context, ConvertMessageType
(loggingEvent.Level), "{0}", new object[] { renderedMessage });
}
catch
{
// consume any exception that would arise...
}

}

private static PBMessageType ConvertMessageType(Level level)
{
PBMessageType msgType;
switch (level.Value)
{
case -2147483648:
case 0x2710:
case 0x4e20:
case 0x7530:
msgType = PBMessageType.Verbose;
break;

case 0xc350:
case 0x9c40:
msgType = PBMessageType.Informational;
break;

case 0xea60:
msgType = PBMessageType.Warning;
break;

case 0x11170:
case 0x13880:
case 0x15f90:
case 0x1d4c0:
case 0x186a0:
case 0x1adb0:
msgType = PBMessageType.Error;
break;

case 0x7fffffff:
msgType = PBMessageType.Internal;
break;

default:
msgType = PBMessageType.Error;
break;
}
return msgType;
}

override protected bool RequiresLayout
{
get { return true; }
}
}

I even tried to write to a text file using StreamWriter to see whether
this appender is being called, but I don't see any proof for it. Here
is how I configured in log4net.config file, which I use the following
code to open the config file:
XmlConfigurator.ConfigureAndWatch(new FileInfo(log4netConfigFile));

<?xml version="1.0" encoding="utf-8" ?>
<log4net>
<root>
<level value="DEBUG" />
<appender-ref ref="FileAppender" />
<appender-ref ref="PaulBunyanAppender" />
</root>
<appender name="FileAppender" type="log4net.Appender.FileAppender">
<file value="C:\pb1log.txt" />
<appendToFile value="true" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger
[%property{NDC}] - %message%newline" />
</layout>
</appender>
<appender name="PaulBunyanAppender"
type="MyApp.Logging.Log4netPaulBunyanAppender, MyApp.Logging">
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="[%thread] - %message" />
</layout>
</appender>
</log4net>

where MyAppp.Logging.dll is the assembly and
MyApp.Logging.Log4netPaulBunyanAppender is the type.

I'm struggling with this for the past few days and any help would be
much appreciated.

Thanks.

My System SpecsSystem Spec
Old 02-25-2009   #2 (permalink)
rh.krish


 
 

Re: log4net: Custom appender not being invoked

I enabled log4net internal debugging and redirected the output to a
text file using trace listener. And I see an error message now:

log4net:ERROR [Log4netPaulBunyanAppender] Failed in DoAppend
System.IO.FileNotFoundException: The specified module could not be
found. (Exception from HRESULT: 0x8007007E)
at Pps.EnterpriseLibrary.Logging.Log4netPaulBunyanAppender.Append
(LoggingEvent loggingEvent)
at log4net.Appender.AppenderSkeleton.DoAppend(LoggingEvent
loggingEvent)

My appender is being invoked, but it's trying to find some dll, and it
could not and throws an exception. I used Red Gate's .NET Reflector
and ildasm to check the assembly and I couldn't find anything missing.
I have all the DLL's in the GAC and I also tried removing them and
linking them privately. Can somebody help me in this?


log4net: log4net assembly [log4net, Version=1.2.10.0, Culture=neutral,
PublicKeyToken=1b44e1d426115821]. Loaded from [Global Assembly Cache].
(.NET Runtime [2.0.50727.42] on Microsoft Windows NT 5.2.3790 Service
Pack 2)
log4net: DefaultRepositorySelector: defaultRepositoryType
[log4net.Repository.Hierarchy.Hierarchy]
log4net: DefaultRepositorySelector: Creating repository for assembly
[Pps.EquipmentTransfer.WebUI, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null]
log4net: DefaultRepositorySelector: Assembly
[Pps.EquipmentTransfer.WebUI, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null] Loaded From [C:\WINDOWS\Microsoft.NET\Framework
\v2.0.50727\Temporary ASP.NET Files\et\ac26e61a\1beceee5\assembly
\dl3\f3f53f44\e737e693_0997c901\Pps.EquipmentTransfer.WebUI.DLL]
log4net: DefaultRepositorySelector: Assembly
[Pps.EquipmentTransfer.WebUI, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null] does not have a RepositoryAttribute specified.
log4net: DefaultRepositorySelector: Assembly
[Pps.EquipmentTransfer.WebUI, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null] using repository [log4net-default-repository] and
repository type [log4net.Repository.Hierarchy.Hierarchy]
log4net: DefaultRepositorySelector: Creating repository [log4net-
default-repository] using type
[log4net.Repository.Hierarchy.Hierarchy]
log4net: XmlConfigurator: configuring repository [log4net-default-
repository] using file [D:\Inetpub\wwwroot\ET
\Pps.EquipmentTransfer.WebUI.log4net.config] watching for file updates
log4net: XmlConfigurator: configuring repository [log4net-default-
repository] using file [D:\Inetpub\wwwroot\ET
\Pps.EquipmentTransfer.WebUI.log4net.config]
log4net: XmlConfigurator: configuring repository [log4net-default-
repository] using stream
log4net: XmlConfigurator: loading XML configuration
log4net: XmlConfigurator: Configuring Repository [log4net-default-
repository]
log4net: XmlHierarchyConfigurator: Configuration update mode [Merge].
log4net: XmlHierarchyConfigurator: Logger [root] Level string is
[DEBUG].
log4net: XmlHierarchyConfigurator: Logger [root] level set to
[name="DEBUG",value=30000].
log4net: XmlHierarchyConfigurator: Loading Appender
[PaulBunyanAppender] type:
[Pps.EnterpriseLibrary.Logging.Log4netPaulBunyanAppender,
Pps.EnterpriseLibrary.Logging, Version=1.0.0.5,
Culture=neutral,PublicKeyToken=63073e399fa578f4]
log4net: DefaultRepositorySelector: Creating repository for assembly
[Pps.EnterpriseLibrary.Logging, Version=1.0.0.5, Culture=neutral,
PublicKeyToken=63073e399fa578f4]
log4net: DefaultRepositorySelector: Assembly
[Pps.EnterpriseLibrary.Logging, Version=1.0.0.5, Culture=neutral,
PublicKeyToken=63073e399fa578f4] Loaded From [Global Assembly Cache]
log4net: DefaultRepositorySelector: Assembly
[Pps.EnterpriseLibrary.Logging, Version=1.0.0.5, Culture=neutral,
PublicKeyToken=63073e399fa578f4] does not have a RepositoryAttribute
specified.
log4net: DefaultRepositorySelector: Assembly
[Pps.EnterpriseLibrary.Logging, Version=1.0.0.5, Culture=neutral,
PublicKeyToken=63073e399fa578f4] using repository [log4net-default-
repository] and repository type
[log4net.Repository.Hierarchy.Hierarchy]
log4net: DefaultRepositorySelector: repository [log4net-default-
repository] already exists, using repository type
[log4net.Repository.Hierarchy.Hierarchy]
log4net: PatternParser: Converter [message] Option [] Format
[min=-1,max=2147483647,leftAlign=False]
log4net: PatternParser: Converter [newline] Option [] Format
[min=-1,max=2147483647,leftAlign=False]
log4net: XmlHierarchyConfigurator: Setting Property
[ConversionPattern] to String value [[%thread] - %message [line#:
%line]]
log4net: PatternParser: Converter [literal] Option [[] Format
[min=-1,max=2147483647,leftAlign=False]
log4net: PatternParser: Converter [thread] Option [] Format
[min=-1,max=2147483647,leftAlign=False]
log4net: PatternParser: Converter [literal] Option [] - ] Format
[min=-1,max=2147483647,leftAlign=False]
log4net: PatternParser: Converter [message] Option [] Format
[min=-1,max=2147483647,leftAlign=False]
log4net: PatternParser: Converter [literal] Option [ [line#:] Format
[min=-1,max=2147483647,leftAlign=False]
log4net: PatternParser: Converter [line] Option [] Format
[min=-1,max=2147483647,leftAlign=False]
log4net: PatternParser: Converter [literal] Option []] Format
[min=-1,max=2147483647,leftAlign=False]
log4net: XmlHierarchyConfigurator: Setting Property [Layout] to object
[log4net.Layout.PatternLayout]
log4net: XmlHierarchyConfigurator: Created Appender
[PaulBunyanAppender]
log4net: XmlHierarchyConfigurator: Adding appender named
[PaulBunyanAppender] to logger [root].
log4net: XmlHierarchyConfigurator: Hierarchy Threshold []
log4net:ERROR [Log4netPaulBunyanAppender] Failed in DoAppend
System.IO.FileNotFoundException: The specified module could not be
found. (Exception from HRESULT: 0x8007007E)
at Pps.EnterpriseLibrary.Logging.Log4netPaulBunyanAppender.Append
(LoggingEvent loggingEvent)
at log4net.Appender.AppenderSkeleton.DoAppend(LoggingEvent
loggingEvent)
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
log4net xmlconfigurator PowerShell
Re: log4net mysteriously stops logging .NET General
PowerShell and Log4Net PowerShell
PS script behavior when invoked from cmd.exe PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46