Try our conversational search powered by Generative AI!

Setup Log4Net

Vote:
 

Have browsed the epiforum on this and also googled other sources for configuring this.
We are running CMS 6 R2. 

I have the standard log.config from episerver. Set <root> section to log level "All", and decommented the default file appender.

I have my class for example purporse "foo.bar.myClass" in namespace "foo.bar".

[ScheduledPlugIn(DisplayName = "MyClass")]
public class myClass
{
	//private static readonly ILog log = LogManager.GetLogger("STF_EPi");
    private static readonly ILog log = LogManager.GetLogger(typeof(myClass));

    public static string Execute()
    {
    	log.Info("Test message");
    }
}
    

 Since nothing is working i have enabled the logging of the log4Net it self.
http://labs.dropit.se/blogs/post/2009/10/14/How-to-log-log4net.aspx

And that is the only thing logging anything so far. I have checked on the logging files and cant se any errors so far. 
Small sample of what is in the log4net loggings. 

log4net: DefaultRepositorySelector: repository [log4net-default-repository] already exists, using repository type [log4net.Repository.Hierarchy.Hierarchy]
log4net: DefaultRepositorySelector: Creating repository for assembly [EPiServer, Version=6.1.379.0, Culture=neutral, PublicKeyToken=8fe83dea738b45b7]
log4net: DefaultRepositorySelector: Assembly [EPiServer, Version=6.1.379.0, Culture=neutral, PublicKeyToken=8fe83dea738b45b7] Loaded From [Global Assembly Cache]
log4net: DefaultRepositorySelector: Assembly [EPiServer, Version=6.1.379.0, Culture=neutral, PublicKeyToken=8fe83dea738b45b7] does not have a RepositoryAttribute specified.
log4net: DefaultRepositorySelector: Assembly [EPiServer, Version=6.1.379.0, Culture=neutral, PublicKeyToken=8fe83dea738b45b7] using repository [log4net-default-repository] and repository type [log4net.Repository.Hierarchy.Hierarchy]
log4net: DefaultRepositorySelector: repository [log4net-default-repository] already exists, using repository type [log4net.Repository.Hierarchy.Hierarchy]
log4net: DefaultRepositorySelector: Creating repository for assembly [EPiServer.XForms, Version=6.1.379.0, Culture=neutral, PublicKeyToken=8fe83dea738b45b7]
log4net: DefaultRepositorySelector: Assembly [EPiServer.XForms, Version=6.1.379.0, Culture=neutral, PublicKeyToken=8fe83dea738b45b7] Loaded From [Global Assembly Cache]
log4net: DefaultRepositorySelector: Assembly [EPiServer.XForms, Version=6.1.379.0, Culture=neutral, PublicKeyToken=8fe83dea738b45b7] does not have a RepositoryAttribute specified.
log4net: DefaultRepositorySelector: Assembly [EPiServer.XForms, Version=6.1.379.0, Culture=neutral, PublicKeyToken=8fe83dea738b45b7] using repository [log4net-default-repository] and repository type [log4net.Repository.Hierarchy.Hierarchy]
log4net: DefaultRepositorySelector: repository [log4net-default-repository] already exists, using repository type [log4net.Repository.Hierarchy.Hierarchy]
log4net: DefaultRepositorySelector: Creating repository for assembly [EPiServer.Shell, Version=6.2.267.1, Culture=neutral, PublicKeyToken=8fe83dea738b45b7]
log4net: DefaultRepositorySelector: Assembly [EPiServer.Shell, Version=6.2.267.1, Culture=neutral, PublicKeyToken=8fe83dea738b45b7] Loaded From [Global Assembly Cache]
log4net: DefaultRepositorySelector: Assembly [EPiServer.Shell, Version=6.2.267.1, Culture=neutral, PublicKeyToken=8fe83dea738b45b7] does not have a RepositoryAttribute specified.
log4net: DefaultRepositorySelector: Assembly [EPiServer.Shell, Version=6.2.267.1, Culture=neutral, PublicKeyToken=8fe83dea738b45b7] using repository [log4net-default-repository] and repository type [log4net.Repository.Hierarchy.Hierarchy]
log4net: DefaultRepositorySelector: repository [log4net-default-repository] already exists, using repository type [log4net.Repository.Hierarchy.Hierarchy]
log4net: DefaultRepositorySelector: Creating repository for assembly [EPiServer.Legacy4, Version=6.1.379.0, Culture=neutral, PublicKeyToken=8fe83dea738b45b7]
log4net: DefaultRepositorySelector: Assembly [EPiServer.Legacy4, Version=6.1.379.0, Culture=neutral, PublicKeyToken=8fe83dea738b45b7] Loaded From [Global Assembly Cache]
log4net: DefaultRepositorySelector: Assembly [EPiServer.Legacy4, Version=6.1.379.0, Culture=neutral, PublicKeyToken=8fe83dea738b45b7] does not have a RepositoryAttribute specified.
log4net: DefaultRepositorySelector: Assembly [EPiServer.Legacy4, Version=6.1.379.0, Culture=neutral, PublicKeyToken=8fe83dea738b45b7] using repository [log4net-default-repository] and repository type [log4net.Repository.Hierarchy.Hierarchy]
log4net: DefaultRepositorySelector: repository [log4net-default-repository] already exists, using repository type [log4net.Repository.Hierarchy.Hierarchy]
log4net: DefaultRepositorySelector: Creating repository for assembly [PageTypeBuilder, Version=1.3.1.0, Culture=neutral, PublicKeyToken=6fb8762af0e6dbed]
log4net: DefaultRepositorySelector: Assembly [PageTypeBuilder, Version=1.3.1.0, Culture=neutral, PublicKeyToken=6fb8762af0e6dbed] Loaded From [C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\6e1fc50b\c0473d3b\assembly\dl3\9fc2e5e5\238a16d2_e697cc01\PageTypeBuilder.DLL]
log4net: DefaultRepositorySelector: Assembly [PageTypeBuilder, Version=1.3.1.0, Culture=neutral, PublicKeyToken=6fb8762af0e6dbed] does not have a RepositoryAttribute specified.
log4net: DefaultRepositorySelector: Assembly [PageTypeBuilder, Version=1.3.1.0, Culture=neutral, PublicKeyToken=6fb8762af0e6dbed] using repository [log4net-default-repository] and repository type [log4net.Repository.Hierarchy.Hierarchy]
log4net: DefaultRepositorySelector: repository [log4net-default-repository] already exists, using repository type [log4net.Repository.Hierarchy.Hierarchy]
log4net: DefaultRepositorySelector: Creating repository for assembly [EPiServer.Scheduler, Version=6.1.379.0, Culture=neutral, PublicKeyToken=8fe83dea738b45b7]
log4net: DefaultRepositorySelector: Assembly [EPiServer.Scheduler, Version=6.1.379.0, Culture=neutral, PublicKeyToken=8fe83dea738b45b7] Loaded From [Global Assembly Cache]
log4net: DefaultRepositorySelector: Assembly [EPiServer.Scheduler, Version=6.1.379.0, Culture=neutral, PublicKeyToken=8fe83dea738b45b7] does not have a RepositoryAttribute specified.
log4net: DefaultRepositorySelector: Assembly [EPiServer.Scheduler, Version=6.1.379.0, Culture=neutral, PublicKeyToken=8fe83dea738b45b7] using repository [log4net-default-repository] and repository type [log4net.Repository.Hierarchy.Hierarchy]
log4net: DefaultRepositorySelector: repository [log4net-default-repository] already exists, using repository type [log4net.Repository.Hierarchy.Hierarchy] 
 
#58066
Apr 12, 2012 14:30
Vote:
 

In AssembyInfo.cs (in folder /Properties/) add:

using log4net.Config;

[assembly: XmlConfigurator(ConfigFile = "EPiServerLog.config", Watch = true)]

And here is a good basic setting:

<?xml version="1.0" encoding="utf-8"?>
<log4net>
	<!-- Use a new log file for each day -->
	<appender name="fileLogAppender" type="log4net.Appender.RollingFileAppender" >
		<file value="C:\Logs\Customer\Customer" />
		<encoding value="utf-8" />
		<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
		<appendToFile value="true" />
		<rollingStyle value="Date" />
		<staticLogFileName value="false" />
		<datePattern value=".yyyyMMdd.'log'" />
		<layout type="log4net.Layout.PatternLayout">
			<conversionPattern value="%date %level [%thread] %type.%method - %message%n" />
		</layout>
	</appender>

	<!-- Log everything concerning site business logic (entire namespace) -->
	<logger name="MyNameSpace.MyOther">
		<level value="DEBUG" />
	</logger>

	<!-- Log when EPiServer saves a page to the database -->
	<logger name="EPiServer.DataAccess.PageSaveDB">
		<level value="Off" />
	</logger>

	<!-- Disable/reduce logging for log-intensive types -->
	<logger name="EPiServer.Events.Remote.RemoteEventsManager">
		<level value="Error" />
	</logger>

	<logger name="EPiServer.Web.InitializationModule">
		<level value="Error" />
	</logger>

	<logger name="EPiServer.Framework.Initialization.InitializationEngine">
		<level value="Error" />
	</logger>

	<!-- Levels: Off, Fatal, Error, Warn, Info, Debug, All -->
	<root>
		<level value="Warn" />
		<appender-ref ref="fileLogAppender" />
	</root>
</log4net>

    

#58067
Apr 12, 2012 15:10
Vote:
 

Have added the assebly lines in my "AssemblyInfo.cs" of the assembly wich my logging is in, but still no sign of any logging.

Has the level value to "All" on root, and fileLogAppender (default unedited epi filelog appender) on.

#58068
Apr 12, 2012 15:19
Vote:
 

Do you have write permissions to that folder?

#58070
Apr 12, 2012 15:29
Vote:
 

There should be good access rights, and in the logging of log4net it self i cannot se any errors at all. I cannot understand why this is not working, so simple yet so hard.

#58071
Apr 12, 2012 15:33
Vote:
 

I dont know  how  the default settings are. But try my  example and check the permissions.

#58072
Apr 12, 2012 15:36
Vote:
 

This is my current log config.

<?xml version="1.0" encoding="utf-8"?>
<log4net>
	<!-- LogAppender used to send log messages to the Log Service
        Values:
        encoding      - has to be set to Unicode
        remoteAddress - ip-address for your log service
        remotePort    - has to be set to the same port as defined in 
                        'udpClientPort' in the configuration file for the log service
                        located in the file %PROGRAMFILES%/EPiServer.LogService5/EPiServer.Log.Service.exe.config
    -->
	<appender name="StatisticsUdpAppender" type="EPiServer.Diagnostics.EPiServerUdpAppender, EPiServer">
		<remoteAddress value="127.0.0.1" />
		<remotePort value="7071" />
	</appender>

	<appender name="fileLogAppender" type="log4net.Appender.FileAppender" >
		<!-- The path is relative to the application base, i.e. the EPiServerSample directory. ASP.NET Machine Account must have modify rights there.
         You probably do NOT want to place it in the application base directory, as it is potentially avaialable to Web site vistors.
         DO CHANGE THE LOCATION BELOW FOR PRODUCTION SYSTEMS -->
		<file value="EPiServerErrorLog.txt" />
		<!-- Typical encoding values are Unicode/utf-16 or utf-8 or ascii. See System.Text.Encoding for more info. Omit this tag to get the system default Ansi -->
		<!-- Use utf-8 for the file appender to conform to EPiServer practices and reduce log file size -->
		<encoding value="utf-8" />
		<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
		<appendToFile value="true" />
		<layout type="log4net.Layout.PatternLayout">
			<!-- You should be aware that generating type and method information is very SLOW -->
			<conversionPattern value="%date %level [%thread] %type.%method - %message%n" />
		</layout>
	</appender>

	<!-- Try the logview4net utility to listen to UDP-logs, download from sourceforge.net -->
	<appender name="udpLogAppender" type="log4net.Appender.UdpAppender" >
		<!-- Typical encoding values are Unicode/utf-16 or utf-8 or ascii. See System.Text.Encoding for more info. Omit this tag to get the system default Ansi -->
		<!-- Use utf-16 since it's default for logvivew4net -->
		<encoding value="utf-16" />
		<!-- Be careful where you send the logs, they may contain sensitive data. You can use 224.0.0.1 for the local net -->
		<remoteAddress value="127.0.0.1" />
		<remotePort value="8082" />
		<layout type="log4net.Layout.PatternLayout">
			<!-- You should be aware that generating type and method information is very SLOW -->
			<conversionPattern value="%date %level [%thread] %type.%method - %message%n%exception" />
		</layout>
	</appender>

	<!-- The RollingFileAppender will create new files according to the settings, typically once every day for example -->
	<appender name="fileStatisticsAppender" type="log4net.Appender.RollingFileAppender">
		<!-- The path is relative to the application base, i.e. the EPiServerSample directory. ASP.NET Machine Account must have modify rights there.
         You probably do NOT want to place it in the application base directory, as it is potentially avaialable to Web site vistors.
         DO CHANGE THE LOCATION BELOW FOR PRODUCTION SYSTEMS -->
		<file value="EPiServerStatisticsLog.txt" />
		<!-- Typical encoding values are Unicode/utf-16 or utf-8 or ascii. See System.Text.Encoding for more info. Omit this tag to get the system default Ansi -->
		<!-- use ASCII to make it easy for other programs to interpret the contents of the statistics log -->
		<encoding value="ascii" />
		<lockingModel type="log4net.Appender.RollingFileAppender+MinimalLock" />
		<appendToFile value="true" />
		<rollingStyle value="Date" />
		<layout type="log4net.Layout.PatternLayout">
			<!-- You should be aware that generating type and method information is very SLOW -->
			<param name="ConversionPattern" value="%date|%message%n" />
		</layout>
	</appender>

	<!-- Statistics are sent to this logger, when enabled  -->
	<logger name="EPiServer.UI.Util.PixelImg">
		<!-- Statistics are sent as 'Info' level logs, set the level to "All" to enable logging, "Off" to disable statistics logging -->
		<level value="All" />
		<appender-ref ref="StatisticsUdpAppender" />
	</logger>

	<!-- Reduce amount of logging from OptimisticCache -->
	<logger name="EPiServer.Core.OptimisticCache" additivity="false">
		<level value="Error" />
	</logger>

	<!-- Reduce amount of logging from DataAccessBase -->
	<logger name="EPiServer.DataAccess.DataAccessBase" additivity="false">
		<level value="Error" />
	</logger>

	<!-- Error and general program flow logs are sent to the root logger. Note that all logs, including statistics if enabled,
       will be sent to these appenders as well -->
	<root>
		<!-- You can use levels, in increasing order of verbosity: Off, Fatal, Error, Warn, Info, Debug, All -->
		<level value="All" />
		<!--level value="Warn" /-->
		<!-- Uncomment one or all of the appender-ref's, or add additional ones -->
		<appender-ref ref="fileLogAppender" />

		<!-- LogView4net is a good application to use to listen to logging output via UDP. Find it on sourceforge. -->
		<!-- appender-ref ref="udpLogAppender" / -->
	</root>
</log4net>

    

#58073
Apr 12, 2012 15:40
Vote:
 

Added your example log config as a new file, changed the AssemblyInfo to this one.
Changed from Warn to All.
Changed ouput path to same directory as the internal log4net log is created, so logicly (i think)  there should be no problem with permissions.

Still no luck though. Still no errors in log4net interal log and no new log file according to the config.

#58075
Apr 12, 2012 15:50
Vote:
 

You can try to use debug output appender and DebugView tool to read logs. In this case you don't depend on any file system and access rights. It's very easy to filter logs and you can see it in real time. Probably you will have to play with options in "Capture"  menu to make it show your logs.

Sample configuration for that:

<?xml version="1.0" encoding="utf-8"?>
<log4net>
 
    <!--Appender to write message to debug output-->
    <appender name="OutputDebugStringAppender" type="log4net.Appender.OutputDebugStringAppender">
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%date [%thread] %-5level %type.%method - %message%newline" />
      </layout>
    </appender>
 
    <root>
      <level value="Debug" />
      <appender-ref ref="OutputDebugStringAppender" />
	</root>
 
</log4net>

I guess you will see errors in DebugView if log4net cannot be initialized. Check also windows event log.

#58076
Edited, Apr 12, 2012 15:55
Vote:
 

Downloaded and ran DebugView but nothing is logged so i guess the log4net is not doing anything. Or im using the program woring.
Looked in the windows event log but finds nothing related, exept that my sheduled job ran "OK" everytime. 

#58078
Apr 12, 2012 16:06
Vote:
 

Under what account is the schedular service running? The scheduled job is not running under the same context as the website.

I'm quite sure it's related to the permissions.

#58084
Apr 12, 2012 17:28
Vote:
 

Do you configure logging for the site of for the Scheduler service? Try to add logging configuration to Scheduler service config file or in log4net.config in service folder.

#58085
Apr 12, 2012 17:44
Vote:
 

The sheduled job plugin code/class is in the same assembly as the main episerver site. And i start the job manually (logged in account in episerver).

#58104
Apr 13, 2012 8:32
Vote:
 

Skipped the code in assembly info and added to the config sections:

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

And then to the AppSettings section:

<add key="log4net.Config" value="log4net.config" />    

And now it is logging as i want it to, though i never got any results in the DebugViewer but it loggs to file as intended.

#58106
Apr 13, 2012 8:58
Vote:
 

Misspelling? log4net.config or EPiServerLog.config?

#58107
Apr 13, 2012 9:03
Vote:
 

Do not add the log4net attribute to assemblyinfo, this is already in place in episerver.dll (is it in the bin directory?) You do not have to add logging settings to web.config, it should all be taken care of for you by the XmlConfigurator attribute in EPiServer.dll. Something else is wrong if it is still not logging.

Make sure you're not affected by this: http://world.episerver.com/Blogs/Steve-Celius/Dates/2010/4/log4net-Tips-Do-not-declare-a-logger-in-Globalasaxcs/

#58110
Edited, Apr 13, 2012 9:47
Vote:
 

We have never used the log4net before in the project so we have not declared any in any global.asax.

The only thing that made the project log anything was adding the log4net section to web.config and define log4net.Config as app setting, and then epi itself started logging when i had it on, epi never logged anything before either. But since it works now i intend to run with the setup.

#58111
Apr 13, 2012 9:51
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.