1
<?xml version="1.0" encoding="UTF-8" ?>
2
<!DOCTYPE html PUBLIC "-//w3c//dtd xhtml 1.1 strict//en" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
3
<html xmlns="http://www.w3.org/1999/xhtml">
5
<link href="style.css" type="text/css" rel="STYLESHEET" />
6
<title>log4net - Frequently Asked Questions</title>
9
<div id="header"><h1>log4net - Frequently Asked Questions</h1>
12
<h2>Frequently Asked Questions</h2>
15
<strong>Summary:</strong> This document contains frequently asked questions about log4net.
18
(Shamelessly copied from the log4j FAQ)
21
<!-- Start Question Links -->
26
<a href="#whatIs">What is log4net?</a>
29
<a href="#reliable">Is log4net a reliable logging system?</a>
32
<a href="#prerequisites">What are the prerequisites for log4net?</a>
35
<a href="#usageExample">Is there example code for using log4net?</a>
38
<a href="#features">What are the features of log4net?</a>
41
<a href="#thread-safety">Is log4net thread-safe?</a>
44
<a href="#sample">What does log output look like?</a>
47
<a href="#logger">What are <em>Loggers</em>?</a>
50
<a href="#tax">Why should I donate my log4net extensions back to the project?</a>
53
<a href="#help">What should I keep in mind when contributing code?</a>
56
<a href="#bugCorrection">How fast do bugs in log4net get fixed?</a>
59
<a href="#history">What is the history of log4net?</a>
62
<a href="#download">Where can I find the latest distribution of log4net?</a>
67
<h2>Configuration</h2>
71
<a href="#behaviour">How can I change log behaviour at runtime?</a>
74
<a href="#disableLogging">How do I completely disable all logging at runtime?</a>
77
<a href="#options">What are the configurable options for an appender?</a>
80
<a href="#filterByLevel">Is it possible to direct log output to different appenders by level?</a>
83
<a href="#configureandwatch">Is there a way to get log4net to automatically reload a configuration file if it changes?</a>
88
<h2>Implemeting Logging</h2>
92
<a href="#namingLoggers">Are there any suggested ways for naming loggers?</a>
95
<a href="#className">How do I get the fully-qualified name of a class in a static block?</a>
98
<a href="#fastLogging">What is the fastest way of (not) logging?</a>
101
<a href="#fasterfasterLogging">What is REALLY the FASTEST way of (not) logging?</a>
104
<a href="#NDC">Can the outputs of multiple client request go to different log files?</a>
107
<a href="#rm">Logger instances seem to be create only. Why isn't there a method to remove logger instances?</a>
110
<a href="#multiProcess">How do I get multiple process to log to the same file?</a>
113
<a href="#timestamp">If I have many process across multiple hosts (possibly across multiple time zones) logging to the same file using the method above, what happens to timestamps?</a>
118
<h2>Customisation</h2>
122
<a href="#customLayouts">Can the log output format be customized?</a>
127
<h2>Troubleshooting</h2>
131
<a href="#internalDebug">How do I enable log4net internal debugging?</a>
134
<a href="#trouble-EventLog">Why doesn't the EventLogAppender work?</a>
137
<a href="#trouble-ASPNET-File">Why can't I log to a FileAppender from a web application?</a>
140
<a href="#troub-Service">Why doesn't the logging in my service work?</a>
143
<a href="#bugs">How do I report bugs?</a>
147
<!-- End Question Links -->
151
<h3><a id="whatIs">What is log4net?</a></h3>
154
log4net is a tool to help the programmer output log statements to a variety of
158
In case of problems with an application, it is helpful to enable logging so
159
that the problem can be located. With log4net it is possible to enable logging at
160
runtime without modifying the application binary. The log4net package is designed
161
so that log statements can remain in <i>shipped</i> code without incurring a
162
high performance cost. It follows that the speed of logging (or rather not
166
At the same time, log output can be so voluminous that it quickly becomes
167
overwhelming. One of the distinctive features of log4net is the notion of <i>hierarchical
168
loggers</i>. Using these loggers it is possible to selectively control
169
which log statements are output at arbitrary granularity.
172
log4net is designed with two distinct goals in mind: speed and flexibility. There
173
is a tight balance between these two requirements.
176
<p><a href="#top">Back to Top</a></p>
179
<h3><a id="reliable">Is log4net a reliable logging system?</a></h3>
182
No. log4net is not reliable. It is a best-effort and <em>fail-stop</em> logging system.
185
By fail-stop, we mean that log4net will not throw unexpected exceptions at
186
run-time potentially causing your application to crash. <b>If for any reason, log4net
187
throws an uncaught exception</b> (except for <span class="code">ArgumentException</span> and
188
<span class="code">ArgumentNullException</span> which may be thrown), <b>please send an email
189
to the <a href="mailto:log4net-users@lists.sourceforge.net">
190
log4net-users@lists.sourceforge.net</a> mailing list</b>. Uncaught exceptions
191
are handled as serious bugs requiring immediate attention.
194
Moreover, log4net will not revert to <span class="code">System.Console.Out</span>
195
or <span class="code">System.Console.Error</span> when its designated
196
output stream is not opened, is not writable or becomes full. This avoids
197
corrupting an otherwise working program by flooding the user's terminal because
198
logging fails. However, log4net will output a single message to
199
<span class="code">System.Console.Error</span> indicating that logging can not be performed.
202
<p><a href="#top">Back to Top</a></p>
205
<h3><a id="prerequisites">What are the prerequisites for log4net?</a></h3>
208
log4net runs on many different frameworks and each framework has its own requirements.
209
As a rule of thumb you will need an ECMA-335 compliant CLI runtime, for example,
210
the Microsoft .NET runtime 1.0 (1.0.3705) or 1.1 (1.1.4322).
213
Not all frameworks are created equal and some features have been excluded from
214
some of the builds. See the <a href="framework-support.html">Framework Support</a>
215
document for more information.
218
<p><a href="#top">Back to Top</a></p>
221
<h3><a id="usageExample">Is there example code for using log4net?</a></h3>
224
There is a directory containing examples in <span class="code">log4net\examples</span>.
225
The examples are broken down by framework.
228
<p><a href="#top">Back to Top</a></p>
231
<h3><a id="features">What are the features of log4net?</a></h3>
235
log4net is optimized for speed.</li>
237
log4net is based on a named logger hierarchy.</li>
239
log4net is fail-stop but not reliable.</li>
241
log4net is thread-safe.</li>
243
log4net is not restricted to a predefined set of facilities.</li>
245
Logging behaviour can be set at runtime using a configuration file.
246
Configuration files are in XML format.</li>
248
log4net is designed to handle exceptions from the start.</li>
250
log4net can direct its output to many sinks including: a file, the console, the NT EventLog or even e-mail.</li>
252
log4net uses 5 levels, namely DEBUG, INFO, WARN, ERROR and FATAL.</li>
254
The format of the log output can be easily changed by implementing a new layout class.</li>
256
The target of the log output as well as the writing strategy can be altered by
257
writing a new appender class.</li>
259
log4net supports multiple output appenders per logger.</li>
262
See the <a href="../features.html">features</a> overview document for more information on the features of log4net.
265
<p><a href="#top">Back to Top</a></p>
268
<h3><a id="thread-safety">Is log4net thread-safe?</a></h3>
271
Yes, log4net is thread-safe.
274
<p><a href="#top">Back to Top</a></p>
277
<h3><a id="sample">What does log output look like?</a></h3>
280
The log output can be customized in many ways. Moreover, one can completely
281
override the output format by implementing one's own <span class="code">ILayout</span>
284
Here is an example output using <span class="code">PatternLayout</span> with the conversion
285
pattern <span class="code">%r [%t] %-5p %c{2} %x - %m%n</span>
288
176 [main] INFO examples.Sort - Populating an array of 2 elements in reverse order.
289
225 [main] INFO examples.SortAlgo - Entered the sort method.
290
262 [main] DEBUG SortAlgo.OUTER i=1 - Outer loop.
291
276 [main] DEBUG SortAlgo.SWAP i=1 j=0 - Swapping intArray[0] = 1 and intArray[1] = 0
292
290 [main] DEBUG SortAlgo.OUTER i=0 - Outer loop.
293
304 [main] INFO SortAlgo.DUMP - Dump of integer array:
294
317 [main] INFO SortAlgo.DUMP - Element [0] = 0
295
331 [main] INFO SortAlgo.DUMP - Element [1] = 1
296
343 [main] INFO examples.Sort - The next log statement should be an error message.
297
346 [main] ERROR SortAlgo.DUMP - Tried to dump an uninitialized array.
298
467 [main] INFO examples.Sort - Exiting main method.
301
The first field is the number of milliseconds elapsed since the start of the
302
program. The second field is the thread outputting the log statement. The third
303
field is the level of the log statement. The fourth field is the rightmost
304
two components of the name of the logger making the log request. The fifth field (just
305
before the '-') is the <em>nested diagnostic context</em> (<span class="code">NDC</span>). Note the
306
nested diagnostic context may be empty as in the first two statements. The text
307
after the '-' is the message of the statement.
310
<p><a href="#top">Back to Top</a></p>
313
<h3><a id="logger">What are <em>Loggers</em>?</a></h3>
316
The notion of loggers lies at the heart of log4net's configuration. Loggers define a
317
hierarchy and give the programmer <em>run-time</em> control on which statements
321
Loggers are assigned levels through the configuration of log4net. A log statement is
322
routed through to the appender depending on its level <em>and</em> its logger.
325
<p><a href="#top">Back to Top</a></p>
328
<h3><a id="behaviour">How can I change log behaviour at runtime?</a></h3>
331
Logging behaviour can be set using configuration files which are parsed at runtime.
332
Using configuration files the programmer can define loggers and set their
336
Configuration files are specified in XML. See <span class="code">log4net.Config.DOMConfigurator</span>
340
See the various <span class="code">log4net.Layout</span> and <span class="code">log4net.Appender</span>
341
components for specific configuration options.
344
<p><a href="#top">Back to Top</a></p>
347
<h3><a id="disableLogging">How do I completely disable all logging at runtime?</a></h3>
350
Setting the <span class="code">Threshold</span> on the Hierarchy to Level OFF will disable all
351
logging from that Hierarchy. This can be done in the log4net configuration file
352
by setting the "threshold" attribute on the log4net configuration element to "OFF".
356
<log4net threshold="OFF" />
359
<p><a href="#top">Back to Top</a></p>
362
<h3><a id="fastLogging">What is the fastest way of (not) logging?</a></h3>
365
For some logger <span class="code">log</span>, writing,
368
log.Debug("Entry number: " + i + " is " + entry[i]);
371
incurs the cost of constructing the message parameter, that is converting both
372
integer <span class="code">i</span> and <span class="code">entry[i]</span> to
373
a string, and concatenating intermediate strings. This, regardless of whether
374
the message will be logged or not.
377
If you are worried about speed, then write
380
if(log.IsDebugEnabled)
382
log.Debug("Entry number: " + i + " is " + entry[i]);
386
This way you will not incur the cost of parameter construction if debugging is
387
disabled for logger <span class="code">log</span>. On the other hand, if the logger is
388
debug enabled, you will incur the cost of evaluating whether the logger is
389
enabled or not, twice: once in <span class="code">IsDebugEnabled</span> and once in <span class="code">Debug</span>.
390
This is an insignificant overhead since evaluating a logger takes less than
391
1% of the time it takes to actually log a statement.
394
<p><a href="#top">Back to Top</a></p>
397
<h3><a id="fasterfasterLogging">What is REALLY the FASTEST way of (not) logging?</a></h3>
400
So you don't think that the previous FAQ is really the fastest way
401
of not logging? Well there is a faster way but it does have some
402
drawbacks. Starting from:
405
if(log.IsDebugEnabled)
407
log.Debug("Entry number: " + i + " is " + entry[i]);
411
It is possible to further eliminate the calls to <span class="code">IsDebugEnabled</span>
412
so that the call is only made once per logger. If you are using one logger
413
for each class then you can store the enabled state for the logger in a static
414
variable in the class and then test against this variable:
417
public class FastLogger
419
private static readonly ILog log = LogManager.GetLogger(typeof(FastLogger));
420
private static readonly bool isDebugEnabled = log.IsDebugEnabled;
422
public void MyMethod()
426
log.Debug("Entry number: " + i + " is " + entry[i]);
432
So why exactly is this faster? Well to start with the <span class="code">IsDebugEnabled</span>
433
is not called for each log statement, it is called once per logger. Furthermore as the
434
<span class="code">isDebugEnabled</span> variable is <span class="code">private static readonly</span>
435
the JIT compiler can at <em>run-time</em> optimise out the <span class="code">if</span> test altogether. This means that
436
at runtime the JIT compiler won't even compile the logging statements into native code, i.e.
437
all the logging just disappears.
440
So what is the downside to using this? Well one of the clever features of log4net is that
441
you can change the logging configuration while your program is running. If you need to
442
investigate an issue in your application, you don't have to stop the application, setup the
443
logging and restart the application, you can change the logging configuration and the
444
log4net will reload it (see <span class="code">ConfigureAndWatch</span> APIs for more
445
information). However if the JIT has compiled out all of the logging statements
446
then they are gone and you can't get them back by reloading the configuration file. Effectively
447
this means that the logging configuration can only be set when the application loads and
448
it cannot be changed at runtime. It is up to you to decide if you need ultimate speed or need
449
to be able to reload the logging configuration while the application is running.
452
<p><a href="#top">Back to Top</a></p>
455
<h3><a id="namingLoggers">Are there any suggested ways for naming loggers?</a></h3>
461
You can name logging loggers by <strong>locality</strong>. It turns out that
462
instantiating a logger in each class, with the logger name equal to the
463
fully-qualified name of the class, is a useful and straightforward approach of
464
defining loggers. This approach has many benefits:
468
It is very simple to implement.</li>
470
It is very simple to explain to new developers.</li>
472
It automatically mirrors your application's own modular design.</li>
474
It can be further refined at will.</li>
476
Printing the logger automatically gives information on the locality of the
480
However, this is not the only way for naming loggers. A common alternative
481
is to name loggers by <strong>functional areas</strong>. For example, the
482
"database" logger, "remoting" logger, "security" logger, or the "XML"
486
You may choose to name loggers by functionality and subcategorize by
487
locality, as in "DATABASE.MyApp.MyClass" or
488
"DATABASE.MyApp.MyModule.MyOtherClass".
491
<em>You are totally free in choosing the names of your loggers.</em> The
492
log4net package merely allows you to manage your names in a hierarchy. However,
493
it is your responsibility to define this hierarchy.
496
<b>Note:</b> by naming loggers by locality one tends to name things by
497
functionality, since in most cases the locality relates closely to
501
<p><a href="#top">Back to Top</a></p>
504
<h3><a id="className">How do I get the fully-qualified name of a class in a static block?</a></h3>
507
You can easily retrieve the fully-qualified name of a class in a static block
508
for class <span class="code">X</span>, with the statement <span class="code">typeof(X).Name</span>.
509
Note that <span class="code">X</span> is the class name and span an instance.
510
However because the <span class="code">LogManager.GetLogger</span> method is overloaded
511
to take an instance of <span class="code">Type</span> as well as <span class="code">string</span>
512
usually only the type of the class is required.
515
Here is the suggested usage template:
520
private static readonly ILog log = LogManager.GetLogger(typeof(Foo));
525
An equivalent and more portable solution, though slightly longer, is to use the declaring type
526
of the static constructor.
531
private static readonly ILog log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
536
<b>Note:</b> the .NET Compact Framework 1.0 does not support <span class="code">System.Reflection.MethodBase.GetCurrentMethod()</span>.
539
<p><a href="#top">Back to Top</a></p>
542
<h3><a id="customLayouts">Can the log output format be customized?</a></h3>
545
Yes. You can implement the <span class="code">ILayout</span> interface to
546
create you own customized log format, or you can extend the
547
<span class="code">LayoutSkeleton</span> class which provides a default
548
implementation of the <span class="code">ILayout</span> interface.
549
Appenders can be parameterized to use the layout of your choice.
552
<p><a href="#top">Back to Top</a></p>
555
<h3><a id="NDC">Can the outputs of multiple client request go to different log files?</a></h3>
558
Many developers are confronted with the problem of distinguishing the log
559
output originating from the same class but different client requests. They come
560
up with ingenious mechanisms to fan out the log output to different files. In
561
most cases, this is not the right approach.
564
It is simpler to use a nested diagnostic context (<span class="code">NDC</span>).
565
Typically, one would <span class="code">NDC.Push()</span>
566
client specific information, such as the client's hostname, ID or any other
567
distinguishing information when starting to handle the client's request.
568
Thereafter, log output will automatically include the nested diagnostic context
569
so that you can distinguish logs from different client requests even if they
570
are output to the same file.
573
See the <span class="code">NDC</span> and the <span class="code">PatternLayout</span> classes for more
577
<p><a href="#top">Back to Top</a></p>
580
<h3><a id="options">What are the configurable options for an appender?</a></h3>
583
log4net uses public properties to configure components such as
584
Appenders, Layouts, Loggers etc.
587
Thus, any writable public property in on the appender corresponds to a
588
configurable option. For example, in <span class="code">RollingFileAppender</span> the
589
<span class="code">public int MaxSizeRollBackups { set; }</span> property corresponds to
590
the <span class="code">MaxSizeRollBackups</span> option.
593
Layouts options are also defined by their writable properties. Same goes for most
594
other log4net components.
597
<p><a href="#top">Back to Top</a></p>
600
<h3><a id="rm">Logger instances seem to be create only. Why isn't there a method to remove logger instances?</a></h3>
603
It is quite nontrivial to define the semantics of a "removed" logger which is
604
still referenced by the user.
607
<p><a href="#top">Back to Top</a></p>
610
<h3><a id="filterByLevel">Is it possible to direct log output to different appenders by level?</a></h3>
613
Yes it is. Setting the <span class="code">Threshold</span> option of any appender extending
614
<span class="code">AppenderSkeleton</span>, (most log4net appenders extend
615
<span class="code">AppenderSkeleton</span>) will filter out all log events
616
with a <em>lower</em> level than the value of the threshold option.
619
For example, setting the threshold of an appender to DEBUG will also allow INFO,
620
WARN, ERROR and FATAL messages to log along with DEBUG messages. (DEBUG is the
621
lowest level). This is usually acceptable as there is little use for DEBUG
622
messages without the surrounding INFO, WARN, ERROR and FATAL messages.
623
Similarly, setting the threshold of an appender to ERROR will filter out DEBUG,
624
INFO and ERROR messages but not FATAL messages.
627
This policy usually best encapsulates what the user actually wants to do, as
628
opposed to her mind-projected solution.
631
<p><a href="#top">Back to Top</a></p>
634
<h3><a id="multiProcess">How do I get multiple process to log to the same file?</a></h3>
637
The <span class="code">FileAppender</span> holds a write lock on the log
638
file while it is logging. This prevents other processes from writing to the
639
file, therefore it is not possible to have multiple processes log directly
640
to the same log file, even if they are on the same machine.
643
You may have each process log to a <span class="code">RemotingAppender</span>.
644
The receiving <span class="code">RemoteLoggingServerPlugin</span> (or
645
<span class="code">IRemoteLoggingSink</span>) can receive all the events and
646
send them to a single log file.
649
<p><a href="#top">Back to Top</a></p>
652
<h3><a id="timestamp">If I have many processes across multiple hosts (possibly across multiple time zones) logging to the same file using the method above, what happens to timestamps?</a></h3>
655
The timestamp is created when the logging event is created. That is so say,
656
when the <span class="code">Debug</span>, <span class="code">Info</span>,
657
<span class="code">Warn</span>, <span class="code">Error</span>
658
or <span class="code">Fatal</span> method is invoked. This is unaffected by the time at
659
which they may arrive at a remote server. Since the timestamps are
660
stored in UTC format inside the event, they all appear in the same time zone as
661
the host creating the logfile. Since the clocks of various machines may not be
662
synchronized, this may account for time interval inconsistencies between events
663
generated on different hosts.
666
<p><a href="#top">Back to Top</a></p>
669
<h3><a id="configureandwatch">Is there a way to get log4net to automatically reload a configuration file if it changes?</a></h3>
672
Yes. The <span class="code">DOMConfigurator</span> supports automatic
673
reloading through the <span class="code">ConfigureAndWatch</span> APIs. See the API
674
documentation for more details.
677
<p><a href="#top">Back to Top</a></p>
680
<h3><a id="tax">Why should I donate my extensions to log4net back to the project?</a></h3>
683
Contrary to the GNU Public License (GPL) the Apache Software License does not
684
make any claims over your extensions. By extensions, we mean totally new code
685
that invokes existing log4net classes. <em>You are free to do whatever you wish with
686
your proprietary log4net extensions.</em> In particular, you may choose to
687
never release your extensions to the wider public.
690
We are very careful not to change the log4net client API so that newer log4net
691
releases are backward compatible with previous versions. We are a lot less
692
scrupulous with the internal log4net API. Thus, if your extension is designed to
693
work with log4net version <span class="code">n</span>, then when log4net release version <span class="code">n+1</span>
694
comes out, you will probably need to adapt your proprietary extensions to the
695
new release. Thus, you will be forced to spend precious resources in order to
696
keep up with log4net changes. This is commonly referred to as the "stupid-tax".
697
By donating the code and making it part of the standard distribution, you save
698
yourself the unnecessary maintenance work.
701
If your extensions are useful then someone will eventually write an extension
702
providing the same or very similar functionality. Your development effort will
706
Unless the proprietary log4net extension is business critical, there is little
707
reason for not donating your extensions back to the project.
710
<p><a href="#top">Back to Top</a></p>
713
<h3><a id="help">What should I keep in mind when contributing code?</a></h3>
717
Stick to the existing indentation style even if you hate it.
719
Alternating between indentation styles makes it hard to understand the source
720
code. Make it hard on yourself but easier on others.
724
<b>Thoroughly test your code.</b>
726
There is nothing more irritating than finding the bugs in debugging (i.e. logging) code.
730
Keep it simple, small and fast.
732
It's all about the application not about logging.
736
Did I mention sticking with the indentation style?</li>
739
<p><a href="#top">Back to Top</a></p>
742
<h3><a id="internalDebug">How do I enable log4net internal debugging?</a></h3>
745
There are several different ways to enable internal debugging in log4net.
746
These different methods are listed below. The prefered method is to sepcify
747
the <span class="code">log4net.Internal.Debug</span> option in the application's
753
To enable log4net's internal debug programmatically you need
754
to set the <span class="code">log4net.helpers.LogLog.InternalDebugging</span>
755
property to <span class="code">true</span>. Obviously the sooner this
756
is set the more debug will be produced.
761
Internal debugging can also be enabled by setting a value in the application's
762
configuration file (not the log4net configuration file, unless the log4net config
763
data is embeded in the application's config file). The <span class="code">log4net.Internal.Debug</span>
764
application setting must be set to the value <span class="code">true</span>.
768
<?xml version="1.0" encoding="utf-8" ?>
769
<configuration>
771
<add key="log4net.Internal.Debug" value="true"/>
773
</configuration>
776
This setting is read immediatly on startup an will cause all internal
777
debugging messages to be emmitted.
782
To enable internal debugging from a configuration file, the
783
<span class="code">debug</span> attribute on the log4net
784
configuration element can be set to the value <span class="code">true</span>.
788
<log4net debug="true">
790
... configuration ...
795
Using this method does require that your configuration file is located
796
and loaded, otherwise the attribute will not be read. If you need to
797
debug the process of locating the configuration file then use one of the other
798
methods for enabling debugging.
803
Internal debugging messages are witten to the console and to the
804
<span class="code">System.Diagnostics.Trace</span>
805
system. If the application does not have a console the messages logged
806
there will be lost. Note that an application can redirect the console
807
stream by setting the <span class="code">System.Console.Out</span>. The
808
Trace system will by default send the message to an attached debugger
809
(where the messages will appear in the output window). If the process
810
does not have a debugger attached then the messages are sent to the
811
system debugger. A utility like DebugView from
812
<a href="http://www.sysinternals.com">http://www.sysinternals.com</a>
813
may be used to capture these messages.
816
<p><a href="#top">Back to Top</a></p>
819
<h3><a id="bugCorrection">How fast do bugs in log4net get fixed?</a></h3>
822
As fast as they get reported ;-)
825
<p><a href="#top">Back to Top</a></p>
828
<h3><a id="history">What is the history of log4net?</a></h3>
831
log4net is a port of the popular <a href="http://jakarta.apache.org/log4j/">log4j</a> logging library.
832
The initial port was done in July 2001, since then we have tried to remain in the
833
spirit of the original log4j.
836
<p><a href="#top">Back to Top</a></p>
839
<h3><a id="bugs">How do I report bugs?</a></h3>
842
Before reporting an issue please check that the question has not been asked before in
843
the <a href="http://sourceforge.net/mailarchive/forum.php?forum=log4net-users">archive</a>.
846
Ask questions and report bugs via email to the <a href="mailto:log4net-users@lists.sourceforge.net">
847
log4net-users@lists.sourceforge.net</a> mailing list.
850
Please specify the version of log4net and the framework you are using. It is helpful to
851
include log configurations files if any, plus source code. A short example reproducing
852
the problem is very much appreciated.
855
If possible please reproduce your issue with the <a href="#internalDebug">internal log4net debugging</a> enabled.
856
Include this debug output in your post, it is usualy the first thing we ask for in diagnosing
860
<p><a href="#top">Back to Top</a></p>
863
<h3><a id="download">Where can I find the latest distribution of log4net?</a></h3>
866
The log4net <a href="http://log4net.sourceforge.net/">home page</a> is a good place to start.
869
The log4net project is hosted at <a href="http://sourceforge.net/projects/log4net/">Sourceforge</a>.
872
<p><a href="#top">Back to Top</a></p>
875
<h3><a id="trouble-EventLog">Why doesn't the EventLogAppender work?</a></h3>
878
If you are not getting events delivered to the event log this usually indicates
879
a permissions problem. Basically if the event log does not exist the EventLogAppender
880
tries to create it, but you need local administrator permissions to create event logs
881
(just to write into the right bit of the registry). You don't need administrator
882
permissions to log to an existing event log, but it must exist. If you are using the
883
event log from a web application or service using the event log can be a little tricky.
886
A web application will run as the user account ASPNET. This account deliberately has
887
few permissions to reduce the chances of someone hacking into the web server. While the
888
account has permission to write to the event log it does not have permission to create
889
event sources (registry create and write access), which are needed to write to the event log.
892
There are a couple of solutions:
897
Make the ASPNET user a member of the Administrators group. This will work because the
898
user will then have the required permissions. This is not recommended for production use.
903
As the event source only needs to be created once for the machine, create an installer
904
and configure it to create the event source.
905
The installer will need to be run as Administrator (don't they all). See
906
<span class="code">System.Diagnostics.EventLogInstaller</span> in the Microsoft .NET
907
Framework SDK for an example of how to create a simple event log installer.
912
<p><a href="#top">Back to Top</a></p>
915
<h3><a id="trouble-ASPNET-File">Why can't I log to a FileAppender from a web application?</a></h3>
918
The web application runs as a special user account on the web server
919
called ASPNET. This account has restricted permissions to protect the
920
web server from attacks. By default this account may not have permission
921
to write to the file system. Make sure that the ASPNET account has
922
permission to create and write to files in the directory chosen for
926
<p><a href="#top">Back to Top</a></p>
929
<h3><a id="troub-Service">Why doesn't the logging in my service work?</a></h3>
932
A windows service runs as a user account specified in the services
933
control panel. This account may have restricted permissions, make
934
sure that the account has permission to create and write to files
935
in the directory chosen for logging.
938
A windows service is launched by windows. The current directory in
939
a service is set to the windows system directory (e.g.
940
<span class="code">C:\Windows\System32</span>). If you are loading
941
the configuration file from the current directory then be aware
942
that this path will not be the location of your assemblies.
943
The best way to get the path to your assemblies is to use
944
<span class="code">AppDomain.BaseDirectory</span>.
945
Note that the log4net internals never use the current directory.
948
<p><a href="#top">Back to Top</a></p>
954
<div id="footer">Copyright (C) 2001-2003 Neoworks Limited. All Rights Reserved.</div>