log4net from my AddIn

D

David Thielen

Hi;

I am trying to use log4net from my AddIn. I created a winword.exe.config
file (below) but the log file is not being created. Is there anything else I
need to do?

<?xml version="1.0"?>
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">

<configSections>
<section name="log4net"
type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
</configSections>

<log4net>
<appender name="RollingFileAppender"
type="log4net.Appender.RollingFileAppender">
<param name="File" value="C:/AutoTag.log" />
<param name="AppendToFile" value="true" />
<param name="MaxSizeRollBackups" value="2" />
<param name="MaximumFileSize" value="100KB" />
<param name="RollingStyle" value="Size" />
<param name="StaticLogFileName" value="true" />
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%d [%t] ac.server %-5p %c - %m%n"
/>
</layout>
</appender>
<root>
<level value="INFO" />
<appender-ref ref="RollingFileAppender" />
</root>
</log4net>


</configuration>
 
P

Peter Huang [MSFT]

Hi David,

Thanks for your posting!
For log4net issue, I suggest you contact in the log4net support.
http://logging.apache.org/log4net/support.html

Also I think you may consider to use .NET buildin feature that log the
Debug or Trace output to a file.
http://www.java2s.com/Code/CSharp/Development-Class/UsingSwitchestoControlDe
bugandTraceTraceSwitch.htm

http://msdn2.microsoft.com/en-us/1txedc80.aspx

e.g. We have an Addin as below.
Public Sub OnConnection(ByVal application As Object, ByVal connectMode
As Extensibility.ext_ConnectMode, ByVal addInInst As Object, ByRef custom
As System.Array) Implements Extensibility.IDTExtensibility2.OnConnection
Debug.WriteLine("Test Debug")
Trace.WriteLine("Test Trace")
End Sub

And use a winword.exe.config as below.
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.diagnostics>
<trace autoflush="true" indentsize="2">
<listeners>
<add name="myListener"

type="System.Diagnostics.TextWriterTraceListener, System,

Version=1.0.3300.0, Culture=neutral,

PublicKeyToken=b77a5c561934e089"

initializeData="MyListener.log"

traceOutputOptions="ProcessId, LogicalOperationStack,

Timestamp, ThreadId, Callstack, DateTime" />
</listeners>
</trace>
</system.diagnostics>
</configuration>


And then the Debug or Trace output will write to the file MyListener.log.

Also .NET class EventLog is also an approach to do the log issue.

If you still have any concern, please feel free to post here.

Best regards,

Peter Huang

Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
D

David Thielen

Let me ask a different question. This is where these values should be set for
any dll that an AddIn uses that is reading config information - correct?

Because for any app I have if I put the below in app.exe.config then it
works. My question is if it looks somewhere else in the case of a dll that an
AddIn calls.
 
P

Peter Huang [MSFT]

Hi David,

Yes, because Office Addin will setup up an Appdomain when the .NET COM
addin is loaded and the cconfig file is per Appdomain.
As I test in my last post, the system.diagnostics element works for the
Word .NET Com Addin

I also have consulted the Office team, the senior engineer suggest that we
explicitly load and read the config file.
We don't recommend using a config file for Word.

If you still have any concern, please feel free to post here.


Best regards,

Peter Huang

Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
D

David Thielen

Hi;

What do you mean by explicitly load & read the config file and it not being
winword.exe.config?
 
P

Peter Huang [MSFT]

Hi David,

For the question, I mean not use Winword.exe.config, we can use our own
config file. It can be a XML file and located in the addin directory.
Because .NET have strongly support for XML, and provided many XML class to
manipulate the XML file.

Also another reason is that, Winword.exe.config is for Winword.exe but we
may have many other Word related application, so to store all the
information in winword.exe.config may cause confliction. Because another
Word Application development may overwrite the existing setting.

If you still have any concern, please feel free to post here.

Best regards,

Peter Huang

Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
D

David Thielen

Hi;

I've looked at the log4net docs and it appears that it must be in
winword.exe.config for log4net. It looks in the app.config file.
 
P

Peter Huang [MSFT]

Hi David,

Based on my test with some config file element, .e.g. the
system.diagnostics or supportedruntime, it all works.

So far I am not sure how the log4net load the config file, but I suggest
you contact the author of the library directly to troubleshooting the load
process.

Since this is a third party library, which is somewhat complex, it is not a
trivial to troubleshoot.

Anyway, if there is a simple reproduce code, it would be better.

If you still have any concern, please feel free to post here.


Best regards,

Peter Huang

Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
P

Peter Huang [MSFT]

Hi David,

Thanks for your understanding!
If you have other questions, please feel free to post here.

Best regards,

Peter Huang

Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
R

raidevnet

Hi,

I'm using log4net with vsto3.0 word and excel addins /wo any problems.

in app.config I use the regular <log4net>...</log4net> stuff and:
<section name="log4net" type="System.Configuration.IgnoreSectionHandler"
/>



in the addin project's AssemblyInfo.cs

// Configure log4net using the .config file
[assembly: log4net.Config.XmlConfigurator(Watch = true)]


Hope this helps,
Rai
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top