Log4net cannot Write database using C# - sql

I have already tried it and found many similar questions, but i can't see one data on my SQL.
Here it's my app.config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
</configSections>
<log4net>
<root>
<level value="ALL"></level>
<appender-ref ref="AdoNetAppender"></appender-ref>
</root>
<appender name="AdoNetAppender" type="log4net.Appender.AdoNetAppender">
<bufferSize value="1" />
<connectionType value="System.Data.SqlClient.SqlConnection, System.Data, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<connectionString value="data source=.;initial catalog=dblog;integrated security=false;persist security info=True;User ID=bernie4;Password=GoodSQL" />
<commandText value="INSERT INTO Log ([Date],[Thread],[Level],[Logger],[Message],[Exception]) VALUES (#log_date, #thread, #log_level, #logger, #message, #exception)" />
<parameter>
<parameterName value="#log_date" />
<dbType value="DateTime" />
<layout type="log4net.Layout.RawTimeStampLayout" />
</parameter>
<parameter>
<parameterName value="#thread" />
<dbType value="String" />
<size value="255" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%thread" />
</layout>
</parameter>
<parameter>
<parameterName value="#log_level" />
<dbType value="String" />
<size value="50" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%level" />
</layout>
</parameter>
<parameter>
<parameterName value="#logger" />
<dbType value="String" />
<size value="255" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%logger" />
</layout>
</parameter>
<parameter>
<parameterName value="#message" />
<dbType value="String" />
<size value="4000" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%message" />
</layout>
</parameter>
<parameter>
<parameterName value="#exception" />
<dbType value="String" />
<size value="2000" />
<layout type="log4net.Layout.ExceptionLayout" />
</parameter>
</appender>
</log4net>
</configuration>
Here is another code ,i tried add to my app.config for code track, but i review my C drive or other position not found the log4net.txt or data.
<configuration>
...
<appSettings>
<add key="log4net.Internal.Debug" value="true"/>
</appSettings>
...
<system.diagnostics>
<trace autoflush="true">
<listeners>
<add
name="textWriterTraceListener"
type="System.Diagnostics.TextWriterTraceListener"
initializeData="C:\tmp\log4net.txt" />
</listeners>
</trace>
</system.diagnostics>
</configuration>
Here is how I'm using C# Create to the log:
using System;
using System.Windows.Forms;
using log4net;
using System.Reflection;
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
log4net.ILog log;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
log4net.Config.XmlConfigurator.Configure();
log = log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
}
private void button1_Click(object sender, EventArgs e)
{
log.Info("your data has been successfully saved.");
}
}
}
if these code successful work , i can see it show string is "your data has been successfully saved" on my SQL ,when i Triggered button1_Click event,but the database not showing nothing.
i watch many people has similar questions ,i tried edit my code,but still useless.
1.bufferSize value="1"
2.log4net.Config.XmlConfigurator.Configure();
3.name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"
finally , here is my software and dll version:
C# :2017
log4net.dll :2.0.8.0 -Net 4.5
SQL :2017

You don't see any logging (including no Log4net debug logging) because your App.config file doesn't get loaded as it isn't valid;
the <configSections> element must be the first child element under <configuration>.
With that in place, you will at least see the internal log4net debug logging.
If the AdoNetAppender has been configured correctly, the database logging will also be present; if not, you can refer to the debug logging.
Your App.config should look like here below.
<configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
<appSettings>
<add key="log4net.Internal.Debug" value="true" />
</appSettings>
<log4net>
<!-- Your log4net configuration goes here -->
</log4net>
<system.diagnostics>
<trace autoflush="true">
<listeners>
<add
name="textWriterTraceListener"
type="System.Diagnostics.TextWriterTraceListener"
initializeData="c:\tmp\log4net.txt" />
</listeners>
</trace>
</system.diagnostics>
</configuration>

Related

Stuck setting up Log4Net - Saving to SQL database [duplicate]

Description
I have a config file as a resource in my assembly and want to change the ConnectionString programmatically in my application.
I load the configuration using log4net.Config.XmlConfigurator.Configure.
I have some breakpoints and see that the configuration is loaded successfuly and the connectionstring is Data Source=localhost\SQLExpress;Initial Catalog=Log;Integrated Security=SSPI; (local SQLExpress).
Problem
Nothing happens, no exception and no log entry. Any ideas.
using (Stream stream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("MyNamespace.Properties.log4net.config"))
{
// stream is NOT null
log4net.Config.XmlConfigurator.Configure(stream);
}
Hierarchy hier = LogManager.GetRepository() as Hierarchy;
if (hier != null)
{
//get ADONetAppender
var adoAppender = (AdoNetAppender)hier.GetAppenders().Where(appender => appender.Name.Equals("AdoNetAppender", StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault();
if (adoAppender != null)
{
// update connectionstring
adoAppender.ConnectionString = configuration.GetConnectionString(ConnectionStringNames.Log).ConnectionString;
//refresh settings of appender
adoAppender.ActivateOptions();
}
}
ILog logger = LogManager.GetLogger("MyProject");
logger.Warn("Test");
content of the log4net.config file
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
</configSections>
<log4net>
<appender name="AdoNetAppender" type="log4net.Appender.ADONetAppender">
<bufferSize value="1" />
<connectionType value="System.Data.SqlClient.SqlConnection, System.Data,
Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<connectionString value="[we will set this automatically at runtime]" />
<commandText value="INSERT INTO Log ([Date],[Level],[Logger],[Message],[Exception])
VALUES (#log_date, #log_level, #logger, #message, #exception)" />
<parameter>
<parameterName value="#log_date" />
<dbType value="DateTime" />
<layout type="log4net.Layout.RawTimeStampLayout" />
</parameter>
<parameter>
<parameterName value="#log_level" />
<dbType value="String" />
<size value="50" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%p" />
</layout>
</parameter>
<parameter>
<parameterName value="#logger" />
<dbType value="String" />
<size value="255" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%c" />
</layout>
</parameter>
<parameter>
<parameterName value="#message" />
<dbType value="String" />
<size value="4000" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%m" />
</layout>
</parameter>
<parameter>
<parameterName value="#exception" />
<dbType value="String" />
<size value="2000" />
<layout type="log4net.Layout.ExceptionLayout" />
</parameter>
</appender>
<root>
<level value="ALL" />
<appender-ref ref="AdoNetAppender" />
</root>
</log4net>
</configuration>
You can debug log4net by hooking into the log4net DebugAppender:
Add a log4net app setting in your app.config file:
<appSettings>
<!-- log4net configuration when running in debug mode. -->
<add key="log4net.Internal.Debug" value="true" />
</appSettings>
Add a debug appender in the log4net config:
<appender name="DebugAppender" type="log4net.Appender.DebugAppender">
<immediateFlush value="true" />
<layout type="log4net.Layout.SimpleLayout" />
</appender>
Add the appender to the log4net config root:
<root>
<level value="ALL" />
<appender-ref ref="AdoNetAppender" />
<appender-ref ref="DebugAppender" />
</root>
When you run your application, look in the output window of Visual Studio and you should see all the internal logging for log4net. If not, then the log4net config file is never loading.
Edit
If you can use a connection string from your app.config file, then remove the connection string from the log4net AdoNetAppender and just call the connection string by name:
<appender name="AdoNetAppender" type="log4net.Appender.AdoNetAppender">
<bufferSize value="1" />
<!-- note: you can use the 4.0 assembly -->
<connectionType value="System.Data.SqlClient.SqlConnection,
System.Data,
Version=4.0.0.0,
Culture=neutral,
PublicKeyToken=b77a5c561934e089" />
<!-- This will retrieve a connection string by name from the app.config -->
<connectionStringName value="ConnectionStringNameFromAppConfig" />
<!-- snip -->
</appender>
Here are some things that I tried that worked out for me...
I wasn't seeing anything because my <appender-ref ref="AdoNetAppender" /> didn't properly reference my <appender name="AdoNetAppender" ... /> in the Web.config. The 'AdoNetAppender' names need to match.
Added <bufferSize value="1" /> to the <appender name="AdoNetAppender" /> section of the Web.config
I created a user account with a password on the SQL server instead of using windows authentication. Granted user access to perform selects and inserts on the table
In Global.asax.cs I initialize log4net using log4net.Config.XmlConfigurator.Configure();
In my C# code I instantiate a new adoAppender object and call logger.Info("save to db");
The documentation on Apache's website is helpful as well ...
http://logging.apache.org/log4net/release/config-examples.html#MS%20SQL%20Server
Hope that saves somebody some time and frustration. Thanks!
I had a log4net configuration running for years, that stopped logging to database this spring 2022.
I solved it by specifying: size value="7" to a DateTime2 database parameter in the log4net configuration. Type in database: datetime2(7), not null.
Why size on that type suddenly is madatory in log4net I don't know.

NServiceBus 5 with RabbitMQ transport throwing exception while enabling UnicastBus

I'm attempting to use NServiceBus with RabbitMQ in a self-hosted scenario. I've obtained the source for the NServiceBus and NServiceBus.RabbitMQ repos on github to track down the issues I've had so far, so the version I'm using is the source on their repos as of yesterday.
Here is my configuration:
var busConfiguration = new BusConfiguration();
busConfiguration.EndpointName("RMAQueue");
busConfiguration.AssembliesToScan(typeof(RMACommand).Assembly);
busConfiguration.Conventions()
.DefiningCommandsAs(type => type.Namespace != null && type.Namespace.StartsWith("RMAInterfaces.Commands.", StringComparison.Ordinal));
busConfiguration.Conventions()
.DefiningEventsAs(type => type.Namespace != null && type.Namespace.StartsWith("RMAInterfaces.Events.", StringComparison.Ordinal));
busConfiguration.Conventions()
.DefiningMessagesAs(type => type.Namespace != null && type.Namespace.StartsWith("RMAInterfaces.Messages.", StringComparison.Ordinal));
busConfiguration.UseTransport<RabbitMQTransport>();
busConfiguration.Transactions().Disable();
busConfiguration.PurgeOnStartup(true);
busConfiguration.UseSerialization<NServiceBus.JsonSerializer>();
busConfiguration.DisableFeature<SecondLevelRetries>();
busConfiguration.DisableFeature<StorageDrivenPublishing>();
busConfiguration.DisableFeature<TimeoutManager>();
busConfiguration.UsePersistence<InMemoryPersistence>();
busConfiguration.EnableInstallers();
var bus = Bus.Create(busConfiguration);
I am getting an exception on the Bus.Create() line:
{"The given key (NServiceBus.LocalAddress) was not present in the dictionary."}
Following the stack from it leads me to see that it's failing while enabling the Feature UnicastBus.
Here is my app config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="MessageForwardingInCaseOfFaultConfig" type="NServiceBus.Config.MessageForwardingInCaseOfFaultConfig, NServiceBus.Core" />
<section name="UnicastBusConfig" type="NServiceBus.Config.UnicastBusConfig, NServiceBus.Core" />
<section name="AuditConfig" type="NServiceBus.Config.AuditConfig, NServiceBus.Core" />
</configSections>
<MessageForwardingInCaseOfFaultConfig ErrorQueue="error" />
<UnicastBusConfig>
<MessageEndpointMappings>
<add Messages="RMAInterfaces" Endpoint="RMAQueue#localhost" />
</MessageEndpointMappings>
</UnicastBusConfig>
<connectionStrings>
<add name="NServiceBus/Transport" connectionString="host=localhost" />
<add name="NServiceBus/Persistence" connectionString="host=localhost"/>
</connectionStrings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1" />
</startup>
<!--<AuditConfig
QueueName="The address to which messages received will be forwarded."
OverrideTimeToBeReceived="The time to be received set on forwarded messages, specified as a timespan see http://msdn.microsoft.com/en-us/library/vstudio/se73z7b9.aspx" />-->
<AuditConfig QueueName="audit" />
</configuration>
What am I missing to be able to self-host NServiceBus using a RabbitMQ transport?
I have just had this exact problem, and the fix is as Andreas suggested. I added the following to my configuration code...
configuration.AssembliesToScan(typeof(NServiceBus.Transports.RabbitMQ.IManageRabbitMqConnections).Assembly);
With that in place the error message regarding NServiceBus.LocalAddress no longer shows up. My complete setup is as follows (code, then config file)
[TestMethod]
public void TestMethod1()
{
LogManager.Use<Log4NetFactory>();
var configuration = new BusConfiguration();
configuration.AssembliesToScan(typeof(NServiceBus.Transports.RabbitMQ.IManageRabbitMqConnections).Assembly);
configuration.UseSerialization<JsonSerializer>();
configuration.UseTransport<NServiceBus.RabbitMQTransport>();
configuration.UsePersistence<InMemoryPersistence>();
var bus = global::NServiceBus.Bus.Create(configuration);
bus.Start();
}
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="MessageForwardingInCaseOfFaultConfig" type="NServiceBus.Config.MessageForwardingInCaseOfFaultConfig, NServiceBus.Core" />
<section name="UnicastBusConfig" type="NServiceBus.Config.UnicastBusConfig, NServiceBus.Core" />
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, Log4net" />
</configSections>
<MessageForwardingInCaseOfFaultConfig ErrorQueue="error" />
<connectionStrings>
<add name="NServiceBus/Transport" connectionString="host=localhost" />
</connectionStrings>
<UnicastBusConfig>
<MessageEndpointMappings>
<add Assembly="TestNSBCreation" Endpoint="TestNSBCreation" />
</MessageEndpointMappings>
</UnicastBusConfig>
<log4net>
<root>
<level value="DEBUG" />
<appender-ref ref="LogFileAppender" />
<appender-ref ref="ContactAppender" />
</root>
<appender name="LogFileAppender" type="log4net.Appender.RollingFileAppender">
<param name="File" value="C:\logs\TestNSBCreation.log" />
<param name="AppendToFile" value="true" />
<rollingStyle value="Size" />
<maxSizeRollBackups value="5" />
<maximumFileSize value="10MB" />
<staticLogFileName value="true" />
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
</layout>
</appender>
</log4net>
</configuration>
The Morgan Skinner's answer helped figure out the actual root cause of my issue. I've added the suggested code configuration.AssembliesToScan(typeof(NServiceBus.Transports.RabbitMQ.IManageRabbitMqConnections).Assembly);
After that the exception was more descriptive. NServiceBus.RabbitMQ package automatically downloads RabbitMQ.Client package. The later package was updated to the latest available on nuget and this created version conflict between what expected by NserviceBus.RabbitMQ and what was actually installed. I've removed both packages completely and reinstalled NserviceBus.RabbitMQ package and the error went away. The ..assembliesToScan... line was no longer needed either.

Log4net does not log to SQL Server 2008 R2 from VS studio 2010

I am trying to Log to SQL Server using Log4net in a WCF Service.I am using Windows authentication and connection to db is fine.
Below are the config File and code.
The File Log is happening correctly.
<configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net"/>
</configSections>
<log4net debug ="true">
<root>
<level value="ALL" />
<appender-ref ref="AdoNetAppender_SqlServer" />
<appender-ref ref="LogFileAppender" />
</root>
<appender name="AdoNetAppender" type="log4net.Appender.AdoNetAppender">
<bufferSize value="1" />
<connectionType value="System.Data.SqlClient.SqlConnection, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<connectionString value="data source=V01KUMAVX\\SQLEXPRESS;initial catalog=dbLog;integrated security=SSPI;" />
<commandText value="INSERT INTO Log ([Date],[Thread],[Level],[Logger],[Message],[Exception]) VALUES (#log_date, #thread, #log_level, #logger, #message, #exception)" />
<parameter>
<parameterName value="#log_date" />
<dbType value="DateTime" />
<layout type="log4net.Layout.RawTimeStampLayout" />
</parameter>
<parameter>
<parameterName value="#thread" />
<dbType value="String" />
<size value="255" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%thread" />
</layout>
</parameter>
<parameter>
<parameterName value="#log_level" />
<dbType value="String" />
<size value="50" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%level" />
</layout>
</parameter>
<parameter>
<parameterName value="#logger" />
<dbType value="String" />
<size value="255" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%logger" />
</layout>
</parameter>
<parameter>
<parameterName value="#message" />
<dbType value="String" />
<size value="4000" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%message" />
</layout>
</parameter>
<parameter>
<parameterName value="#exception" />
<dbType value="String" />
<size value="2000" />
<layout type="log4net.Layout.ExceptionLayout" />
</parameter>
</appender>
</log4net>
</configuration>
and the code :
public class Service1 : IService1
{
private static readonly log4net.ILog log;
static Service1()
{
log4net.Config.XmlConfigurator.Configure();
log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
}
public string GetData(int value)
{
log4net.Config.XmlConfigurator.Configure();
log.Debug(string.Format("You entered: {0}", value));
if (!log4net.LogManager.GetRepository().Configured)
{
// log4net not configured
foreach (log4net.Util.LogLog message in log4net.LogManager.GetRepository().ConfigurationMessages)
{
// evaluate configuration message
}
}
return string.Format("You entered: {0}", value);
}
}
How to Log the Log4net Silent errors and how to view them ?
Your Appender names don't match:
<appender name="AdoNetAppender" type="log4net.Appender.AdoNetAppender">
vs.
<appender-ref ref="AdoNetAppender_SqlServer" />
Change them both to be "AdoNetAppender" or "AdoNetAppender_SqlServer" so that they match (doesn't matter which).

log4net not inserting into database but working fine for file

I am using this code in WCF application in VS 2012, SQL Express is 2008 R2.
I have included the fileAppendor and Database Appendor, File Appender works fine but its not inserting data into the database.
I have verified the same connection string its working fine and inserting records in to the table.
Also I have set the buffer value to 1, still no luck
<bufferSize value="1" />
This is my config file
<?xml version="1.0"?>
<configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
</configSections>
<log4net>
<appender name="AdoNetAppender" type="log4net.Appender.AdoNetAppender">
<bufferSize value="1" />
<connectionType value="System.Data.SqlClient.SqlConnection, System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<connectionString value="server=(local)\\SQLEXPRESS;database=Log_DB;Integrated Security=SSPI;Connection Timeout=360;" />
<connectionString value="data source=[(local)\\SQLEXPRESS];initial catalog=[Log_DB];integrated security=SSPI" />
<commandText value="INSERT INTO [Error_Log] ([Date_time] ) VALUES (#Date_time)" />
<parameter>
<parameterName value="#Date_time" />
<dbType value="DateTime" />
<!--<layout type="log4net.Layout.RawTimeStampLayout" />-->
<layout type="log4net.Layout.PatternLayout" value="%date{yyyy'-'MM'-'dd HH':'mm':'ss'.'fff}" />
</parameter>
</appender>
<appender name="LogFileAppender" type="log4net.Appender.FileAppender">
<file value="log-file.txt"/>
<appendToFile value="true"/>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger [%ndc] ID=%property{EventID} - %message%newline" />
</layout>
</appender>
<!-- Setup the root category, add the appenders and set the default level -->
<root>
<level value="ALL" />
<appender-ref ref="LogFileAppender" />
<appender-ref ref="AdoNetAppender" />
</root>
</log4net>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
<add key="log4net.Internal.Debug" value="true"/>
</appSettings>
...
</configuration>
Do I am missing any other stuff?
Also I am not getting any information by setting Internal.Debug to true.
How to get internal debug details of log4net?
Finaly I got the answer for this, I am sharing here since it may help others.
Need to use the System/Machine Name instead of (local) in the Connection string. Even with the dotnet application (local) works but for log4net need to use the System name.

ASP.NET MVC with Castle Logging and log4net woes

In my installer, I have
public void Install(IWindsorContainer container, IConfigurationStore store)
{
container.AddFacility<LoggingFacility>(f => f.UseLog4Net("log4net.config"));
}
My log4net config file (which gets deployed to the bin directory of my ASP.NET MVC app) is:
<log4net>
<appender name="AdoNetAppender" type="log4net.Appender.AdoNetAppender">
<bufferSize value="100" />
<connectionType value="System.Data.SqlClient.SqlConnection, System.Data, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<connectionString value="data source=GCO06773\SQLEXPRESS;initial catalog=GEMS;integrated security=false;persist security info=True;User ID=<<userid removed>>;Password=<<password removed>>#" />
<commandText value="INSERT INTO Log ([Date],[Thread],[Level],[Logger],[Message],[Exception]) VALUES (#log_date, #thread, #log_level, #logger, #message, #exception)" />
<parameter>
<parameterName value="#log_date" />
<dbType value="DateTime" />
<layout type="log4net.Layout.RawTimeStampLayout" />
</parameter>
<parameter>
<parameterName value="#thread" />
<dbType value="String" />
<size value="255" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%thread" />
</layout>
</parameter>
<parameter>
<parameterName value="#log_level" />
<dbType value="String" />
<size value="50" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%level" />
</layout>
</parameter>
<parameter>
<parameterName value="#logger" />
<dbType value="String" />
<size value="255" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%logger" />
</layout>
</parameter>
<parameter>
<parameterName value="#message" />
<dbType value="String" />
<size value="4000" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%message" />
</layout>
</parameter>
<parameter>
<parameterName value="#exception" />
<dbType value="String" />
<size value="2000" />
<layout type="log4net.Layout.ExceptionLayout" />
</parameter>
</appender>
<root>
<level value="INFO" />
<appender-ref ref="AdoNetAppender" />
</root>
</log4net>
I have a controller that's instantiated via Castle.Windsor The relevant code is:
public ILogger Logger { get; set; }
public ActionResult Index()
{
Logger.Info("Info");
Logger.Debug("Debug");
Logger.Error("Error");
Logger.Fatal("Fatal");
Logger.Warn("Warn");
return View();
}
The Logger is a valid castle logger and when I delve into it in the watch window, it appears that there are no appenders associated with the underlying log4net logger, except for the root appender.
According to procmon, the log4net.config file is actually being accessed at some point, so I'm assuming it's being read. I get no errors in the IIS log, no errors in the event log and no exceptions or errors that I can detect. I'm stumped.
UPDATE 1:
Forgot to mention, I added this:
<add key="log4net.Config" value="log4net.config"/>
to the web.config, but it didn't seem to change anything.
UPDATE 2:
I'm using Log4Net 1.2.10.0 with public key token: 1b44e1d426115821 (this matters with Castle Logging which is why I mention it).
The log4net.config file should be in root of your web, not in bin directory.