I’m working on a project with some custom Sharepoint Workflow components which I’d like to add log4net to.
I’m really struggling to get log4net to output anything at all though!
Here’s my current setup:
In the codebehind for my Workflow:
private ILog log;
public MessageQueueWorkflow()
{
InitializeComponent();
string filepath = ConfigurationManager.AppSettings["log4netConfigPath"];
if (!string.IsNullOrEmpty(filepath))
{
log4net.Config.XmlConfigurator.ConfigureAndWatch(new FileInfo(filepath));
log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
}
}
public Guid workflowId = default(System.Guid);
public SPWorkflowActivationProperties workflowProperties = new SPWorkflowActivationProperties();
private void onWorkflowActivated1_Invoked(object sender, ExternalDataEventArgs e)
{
try
{
#region Logging
if (log.IsDebugEnabled)
{
log.Debug(System.Reflection.MethodInfo.GetCurrentMethod().Name);
}
#endregion Logging
// do some stuff
}
catch (Exception ex)
{
if (log.IsErrorEnabled)
{
log.Error("An error has occurred.", ex);
}
throw ex;
}
}
In my web.config for the Sharepoint site:
<appSettings>
<add key="log4netConfigPath" value="C:\Inetpub\wwwroot\wss\VirtualDirectories\80\log4net.config"/>
</appSettings>
In my log4net.config file:
<log4net debug="true">
<appender name="EventLogAppender" type="log4net.Appender.EventLogAppender" >
<applicationName value="MyApp" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%d %-5p %c - %m%n" />
</layout>
</appender>
</log4net>
Now, when I run this workflow, I’d expect to see some debug entries showing up in the EventViewer, but I’m getting nothing.
Any ideas what I’m doing wrong?
Thanks!
You need to configure at least one logger. Usually you would configure the root logger. E.g.:
If this is not making it work yet, the I recommend that you configure a trace listener that will output the log4net internal debugging messages. (You already have internal debugging turned on.)