log4net is unable to load the file MySql.Data from GAC - log4net

I am trying to evaluate the use of log4net for my new Windows Services platform. I was hoping to use generate logs in my MySql database.
I have the latest of MySql (6.9.4.0) and log4net.
I have a create a simple windows console application and to that added a configuration file log4net.config which has my appender information.
Added the following line of code to AssemblyInfo class
[assembly: XmlConfigurator(ConfigFile = "log4net.config", Watch = true)]
and the following in my Program class
private static readonly ILog _debugLogger = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
I have both log4net and MySql.Data Gaced in GAC_MSIL and both assemblies added to assemblyBinding section of the Application.config file
When I execute the program I see no logs generated. On turning on Apaches internal logging i see the error that it failed to load the MySql.Data file
Copy MySql.Data file to bin folder and the logs are generated absolutely fine.
Any clues?
Thanks
Regards
Sid

My bad. The connection type element in the appender was missing the complete assembly name. It had MySql.Data.MySqlClient.MySqlConnection, MySql.Data
but should have had
MySql.Data.MySqlClient.MySqlConnection, MySql.Data, Version=6.9.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d
Works fine.

Related

How to specify log file path with log4net.config?

In my log4net.config I put
<appender name="Access" type="log4net.Appender.RollingFileAppender">
<file type="log4net.Util.PatternString" value="%envFolderPath{CommonApplicationData}\MyApp\test.txt"/>
& my code for configuration is
XmlDocument log4netConfig = new XmlDocument();
log4netConfig.Load(File.OpenRead("log4net.config"));
var repo = log4net.LogManager.CreateRepository(Assembly.GetEntryAssembly(),
typeof(log4net.Repository.Hierarchy.Hierarchy));
log4net.Config.XmlConfigurator.Configure(repo, log4netConfig["log4net"]);
but it didn't creating file at 【C:\ProgramData\MyApp】.
I also tried using
%envFolderPath{ApplicationData}
%envFolderPath{ProgramData}
Any ideas.
Thank you!
Works fine on my machine. You can try to debug it with steps:
Try to log information to some hardcoded path like C:\temp to make sure, your configuration is working fine.
Add reference to System.Configuration.ConfigurationManager to make sure all librieries are in place
Use this line to configure log4net:
XmlConfigurator.Configure(LogManager.GetRepository(Assembly.GetEntryAssembly()), new FileInfo("log4net.config"));
Make sure you have enough permission to write to Special Folders.
Create new Console Application in .net core with the same configuration, and enable internal debugging:
log4net.Util.LogLog.InternalDebugging = true;
You will see exactly what's going on. You will see what paths your application is using and you will see any errors that occurs during internal log4net configuration.

ServiceStack Log4NetFactory

How can I configure log4net in code when I like to use the servicestack logging interface? I see there is
LogManager.LogFactory = new Log4NetFactory(configureLog4Net:true);
If I got things right this expects a XML file containing the Log4Net configuration. I avoid XML config files whenever possible and usually configure Log4Net with my own static LoggerConfig class. There I setup all my appenders (EventLog, File, Console, etc.) using the Log4Net API.
Is there any way to integrate my class with the ServiceStack logging interface?

Configure Eclipse for Log4j

I am working on an application using apache jena, to access dbpedia using sparql. Well I am very new to DBPedia and apache jena, I did some research and started with some sample code to create VCARD.
public class DpPedia extends Object {
static String personURI = "<!..http://def/JohnSmith..!>";
static String fullName = "John Smith";
static String Fullname = "Pulkit Gupta";
public static void main (String args[]) {
// create an empty model
Model model = ModelFactory.createDefaultModel();
// create the resource
Resource johnSmith = model.createResource(personURI);
Resource pulkitgupta=model.createResource(personABC);
// add the property
johnSmith.addProperty(VCARD.FN, fullName);
pulkitgupta.addProperty(VCARD.FN,Fullname);
}
}
However when i tried to execute this code .. It end up with an error
log4j:WARN No appenders could be found for logger (org.apache.jena.riot.stream.JenaIOEnvironment).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
it seems my eclipse is not configured properly and I need to install Log4j. Well I downloaded the files, but not sure how up configure it with eclipse.
jena use log4j as logging system, and the warning messages tell explicitly that you are lacking of a log4j.properties to initialize it.
"This occurs when the default configuration files log4j.properties and log4j.xml can not be found and the application performs no explicit configuration."
Create log4j.properties file under src and retry. You can find some sample config files here
The easiest way to do this is by going to the folder where you extracted apache jena.
Find a properties file named : jena-log4j.properties. Copy this
Navigate to your workspace folder where you have your source project.
Go to bin folder and paste the file there. Make sure you rename the file to just log4j.properties
Clean the project and run it.
The errors would now have gone.
use org.apache.log4j.Logger.getRootLogger().setLevel(org.apache.log4j.Level.OFF);

log4j produces no output on specific Weblogic servers

We are distributing an application that is deployed as a bunch of WAR files in various WebLogic servers (9, 10 and 11) at various customers' sites. Those apps are using commons-logging and log4j. It works perfectly everywhere except at a specific site where no logs are generated from our app. That site is on 11g and has a bunch of other Oracle software installed (BPEL, OSB etc)
In our code, we use:
public class Foo {
private final static Log log = LogFactory.getLog(Foo.class);
public void bar () {
log.trace("bar called");
...
Since we want to let the customers adapt their logs configuration, we have a configuration folder in the server CLASSPATH:
CLASSPATH=/opt/app/domain_foo/foo_config/:....
In that folder, two files for logs, commons-logging.properties:
org.apache.commons.logging.Log org.apache.commons.logging.impl.Log4JLogger
And log4j.properties: (this is a simplified one that has the same issue, actual file contains 5 loggers with various parameters)
log4j.rootLogger=INFO, fileApp
# File appender
log4j.appender.fileApp=org.apache.log4j.RollingFileAppender
log4j.appender.fileApp.file=fooapp.log
log4j.appender.fileApp.maxFileSize=10240KB
log4j.appender.fileApp.maxBackupIndex=5
log4j.appender.fileApp.append=true
log4j.appender.fileApp.layout=org.apache.log4j.PatternLayout
log4j.appender.fileApp.layout.ConversionPattern=%d{dd/MM/yyyy HH:mm:ss,SSS} %-5p %-70.70C %m%n
log4j.logger.be.foo=DEBUG
The file fooapp.log is created (so it was able to find the properties file) but empty.
I tried to check the log settings in Weblogic but they seem to be the same on working and not working servers.
I copied the CLASSPATH to my server and it is still working fine.
I don't really know where to look anymore. Any ideas ?
It is a bit tricky but the answer is in the environment named: APPLICATIONS_DIRECTORY that should point to the path where APPLICATIONS_DIRECTORY/fooapp.log should be. You can get the directory location from System.getenv("APPLICATIONS_DIRECTORY");

how to change the logging level of logger in the code overriding value set on config

I have a C# Win Form application and in each class i get the logger like this:
private static readonly ILog Log = LogManager.GetLogger("ApplnLogger");
I configured in my app.config to log messages at info level and above.
Now when a issue is reported i would like to set the logger level to debug so that i will have information in log file necessary for debugging the issue.
How do I set the logger level to debug overriding the config level of INFOwithout having to restart my win form application?
Check out ConfigureAndWatch
Basically, you tell your program to watch the configuration file for changes. So, if you edit this file, Log4net will automatically use the new settings without you having to restart your application.

Resources