log4net-configuration

MSTest - How do I initialize log4net for a UnitTest project?

早过忘川 提交于 2019-12-21 07:21:06
问题 I have a Visual Studio unit test project for testing an ASP.NET MVC project. Adding the assembly-level log4net.Config.XmlConfigurator attribute to AssemblyInfo.cs doesn't work and other people on SO have found they have to use a direct call to log4net.Config.XmlConfigurator.Configure(); The question is, how can this be done for a unit test? The answer to use Microsoft.VisualStudio.TestTools.UnitTesting.AssemblyInitialize attribute on a class method doesn't work. For me, this code results in

Configuring log4net appenders via XML file *and* code

荒凉一梦 提交于 2019-12-20 03:22:07
问题 I started to play with log4net today and so far, I really like it. In order to preserve our current logging functionality, the app needs to create a new log file whenever the application is started. The log file name has the date and time stamp encoded in it. Currently, I've got log4net configured via an XmlConfigurator , which works great, except that the filename for my RollingFileAppender is hardcoded in the configuration XML file. I'd like to continue to use the XmlConfigurator , but

log4net set from an external config file not working

痞子三分冷 提交于 2019-12-18 08:40:20
问题 I'm having a weird issue with log4net. In an ASP.NET application, I want to configure log4net externally, so I have a separate log4net.config file which I hook up to my web app with this line in the AssemblyInfo.cs file belonging to my web app: [assembly: log4net.Config.XmlConfigurator(ConfigFile = "Log4Net.config", Watch = true)] Now, if I instantiate the log4net logger class the normal way like this: public class MyClass { private static readonly ILog _logger = log4net.LogManager.GetLogger

Exception when adding log4net config

送分小仙女□ 提交于 2019-12-18 04:41:59
问题 I am getting an error on the very first line of code in the App.cs file (which is creating a readonly variable). The error I am getting is: A first chance exception of type 'System.TypeInitializationException' occurred in PresentationFramework.dll An unhandled exception of type 'System.TypeInitializationException' occurred in PresentationFramework.dll Additional information: The type initializer for 'System.Windows.Application' threw an exception. This is the message popup I get in VS: An

log4net initialisation

大兔子大兔子 提交于 2019-12-17 16:27:03
问题 I've looked hard for duplicates but have to ask the following, no matter how basic it may seem, to get it clear once and for all! In a fresh Console app using log4net version 1.2.10.0 on VS28KSP1 on 64 bit W7, I have the following code:- using log4net; using log4net.Config; namespace ConsoleApplication1 { class Program { static readonly ILog _log = LogManager.GetLogger(typeof(Program)); static void Main(string[] args) { _log.Info("Ran"); } } } In my app.config , I have: <?xml version="1.0"

log4net filter - how to write AND filter to ignore log messages

时间秒杀一切 提交于 2019-12-17 16:17:03
问题 I am struggling to write an AND conditional filter in log4net. Had it been nLog, I could have written it this way: <logger name="*" minlevel="Info" xsi:type="NLogLoggerRule" writeTo="FooLogger" > <filters> <when condition="equals('${event-context:item=UserID}', 'TESTUSER') and equals('${event-context:item=URL}','/foo/foobar.aspx')" action="Ignore" /> </filters> </logger> I am not sure how to write the same filter in log4net. I have been so far successful, in writing a single condition:

How to disable creation of empty log file on app start?

荒凉一梦 提交于 2019-12-17 07:30:10
问题 I have configured log4net in my app successfully but one thing is a little bit annoying for me. The log file is created (empty) after my app start even if no error occurs. I would like to log file be created only after some error. 回答1: I actually found a way to do this in this thread: http://www.l4ndash.com/Log4NetMailArchive/tabid/70/forumid/1/postid/18271/view/topic/Default.aspx I've tested the first method and it works. Just in case that link is not longer good I'll reproduce the code here

Configuring log4net to write on a database

China☆狼群 提交于 2019-12-13 09:17:01
问题 I am trying to configure log4net to log in the database, it is already configured to write in a file, but when I change the appender to the database it doesn't do anything. The connection to the database is ok because if I change the password I can see an entry in the eventviewer saying the password is wrong. Here it is my app.config: <log4net> <appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender"> <layout type="log4net.Layout.PatternLayout"> <conversionPattern value="%date

extend log4net SmtpAppender for dynamic To email address

牧云@^-^@ 提交于 2019-12-13 05:37:29
问题 Ok. I have created custom SmtpAppender to use dynamic To email address. Using sample project given with Log4net - I have managed to use dynamic email address as below log4net.ThreadContext.Properties["ToProperty"] = "swapneel@stackoverlfow.com"; and in my custom SMTPAppender string mailMessageTo; if (ToProperty == null) { mailMessageTo = "DoNotReply@StaockOverlfow.com" } else { var subjectWriter = new StringWriter(System.Globalization.CultureInfo.InvariantCulture); ToProperty.Format

Log4Net programmatically check IsEnabledFor for Appender filters

微笑、不失礼 提交于 2019-12-12 15:10:19
问题 How do I programmatically check that IsEnabledFor is true for a certain appender filter. This is my config: <log4net> <root> <level value="ALL" /> <appender-ref ref="appender" /> </root> <appender name="appender" type="log4net.Appender.FileAppender"> <filter type="log4net.Filter.LevelRangeFilter"> <levelMin value="ERROR" /> <levelMax value="FATAL" /> </filter> </appender> <log4net> Ok so if I set <root> Level to say ERROR and I do a IsEnabledFor (Debug) it returns true but if I set <root>