Daniel, If I run with your config I get the following message in the Debug Output window in VisualStudio:
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender [FileAppender] of type [log4net.Appender.FileAppender]. Reported error follows. System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed. at System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet) at System.Security.CodeAccessPermission.Demand() at System.IO.Path.GetFullPath(String path) at log4net.Util.SystemInfo.ConvertToFullPath(String path) at log4net.Appender.FileAppender.ConvertToFullPath(String path) at log4net.Appender.FileAppender.ActivateOptions() at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlE lement appenderElement) The action that failed was: Demand The type of the first permission that failed was: System.Security.Permissions.FileIOPermission The Zone of the assembly that failed was: MyComputer Looks like you don't have FileIOPermission in the Medium trust zone! If this is the case on your deployment platform then you can't log to a file! Cheers, Nicko > -----Original Message----- > From: Daniel Miller [mailto:[EMAIL PROTECTED] > Sent: 10 July 2006 13:47 > To: 'Log4NET User' > Subject: RE: ASP .NET 2.0 Security error - Config problems - > Any ideas? > > Hi Nicko > > Still no luck. See the full web.config below. > With trust-level = Medium, it fails; without it, it succeeds. > > Any other ideas? > > Daniel > > <?xml version="1.0"?> > <configuration> > <configSections> > <section name="log4net" > type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" > requirePermission="false" /> > </configSections> > > <appSettings> > <add key="CONTACT_EMAIL" value="[EMAIL PROTECTED]"/> > <add key="SMTP_SERVER" value="mail.my-domain.com"/> > </appSettings> > <connectionStrings/> > > <system.web> > <trust level="Medium"/> > <customErrors mode="Off" > defaultRedirect="~/home/maintenance.aspx"> > <error statusCode="404" redirect="~/home/page_not_found.aspx"/> > </customErrors> > <urlMappings enabled="true"> > <add url="~/default.aspx" > mappedUrl="~/home/default.aspx"/> > </urlMappings> > <compilation debug="true"/> > <authentication mode="Windows"/> > </system.web> > <log4net debug="false"> > <appender name="FileAppender" > type="log4net.Appender.FileAppender"> > <param name="File" value="..\logs\log-file.txt" /> > <param name="AppendToFile" value="true" /> > <layout type="log4net.Layout.PatternLayout"> > <param name="ConversionPattern" value="%d %-5p %c - %m%n" /> > </layout> > </appender> > <appender name="SmtpAppender" > type="log4net.Appender.SmtpAppender,log4net"> > <to value="[EMAIL PROTECTED]" /> > <from value="[EMAIL PROTECTED]" /> > <subject value="WOWO log message" /> > <smtpHost value="mail.my-domain.com" /> > <bufferSize value="1" /> > <lossy value="false" /> > <threshold value="DEBUG" /> > <evaluator type="log4net.Core.LevelEvaluator,log4net"> > <threshold value="DEBUG" /> > </evaluator> > <layout type="log4net.Layout.PatternLayout,log4net"> > <conversionPattern value="%level :: %message %newlineLogger: > %logger%newlineThread: %thread%newlineDate: %date%newline%newline" /> > </layout> > </appender> > <root> > <appender-ref ref="SmtpAppender"/> > <appender-ref ref="FileAppender"/> > <level value="ALL"/>" > </root> > </log4net> > </configuration> > > -----Original Message----- > From: Nicko Cadell [mailto:[EMAIL PROTECTED] > Sent: Monday, July 10, 2006 3:06 PM > To: Log4NET User > Subject: RE: ASP .NET 2.0 Security error - Config problems - > Any ideas? > > Daniel, > > The 2 changes, adding the requirePermission="false" and calling > XmlConfigurator.Configure() from the Application_Start, do > fix the ConfigurationPermission exception that you were > seeing. Unfortunately you then run smack into another > SecurityException! This is caused by the LogicalThreadContext. > > You can work around this by not outputting any of the context > properties or stacks (i.e. %ndc or %property). Can you do > this to verify that this is the issue? (i.e. change your > appender's layout configuration to something like:) > > <layout type="log4net.Layout.PatternLayout" value="%date > [%thread] %-5level %logger - %message%newline" /> > > > Fixing the SecurityException requires a code change to the > log4net library. > > http://issues.apache.org/jira/browse/LOG4NET-79?page=all > http://svn.apache.org/viewvc?view=rev&revision=420499 > > If you need to log property values you will need to build > your own copy of the log4net library including the changes > above. Either get the latest source from SVN or use the > source from the 1.2.10 release and manually apply the above changes. > > Cheers, > Nicko > > > -----Original Message----- > > From: Daniel Miller [mailto:[EMAIL PROTECTED] > > Sent: 10 July 2006 09:47 > > To: 'Log4NET User' > > Subject: RE: ASP .NET 2.0 Security error - Config problems - Any > > ideas? > > > > Thanks Nicko and Ron for your help. > > > > I tried both suggestions but still no luck. > > > > In web.config I have: > > > > <configSections> > > <section name="log4net" > > type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" > > requirePermission="false" /> > > </configSections> > > > > as well as the log4net config section. > > > > In Global.asax, in method "Application_Start" I have: > > > > log4net.Config.XmlConfigurator.Configure(); > > > > The thing is, on my local machine it works (the test logs appear in > > the log file), but when I add <trust level="Medium"/> to > web.config to > > simulate the host server, it doesn't work. No error message is > > generated either. I uploaded the code to my web host too > and find the > > same results. > > > > What am I missing here? > > > > Daniel > > > > -----Original Message----- > > From: Ron Grabowski [mailto:[EMAIL PROTECTED] > > Sent: Sunday, July 09, 2006 8:51 PM > > To: Log4NET User > > Subject: Re: ASP .NET 2.0 Security error - Config problems - Any > > ideas? > > > > See if this works: > > > > log4Net and ASP.Net Medium Trust > > http://tinyurl.com/njqh4 > > http://blogs.advantaje.com/blog/kevin/Net/2006/06/29/log4Net-a > > nd-ASP-Net-Med > > ium-Trust.html > > > > --- Daniel Miller <[EMAIL PROTECTED]> wrote: > > > > > Hi there > > > > > > > > > > > > I'm using log4net with an ASP .NET 2.0 application. On my local > > > machine all works well, but when deployed to an ISP, there are no > > > logs. > > > > > > > > > > > > After much debugging, I discovered that log4net was failing on a > > > "Security Error" (see error message below) - i.e., the > > server's trust > > > level is Medium and blocks log4net from reading the config > > data. (When > > > I used a separate log4net.config file this error was > swallowed; it > > > only showed up when I moved the config data to web.config). > > > > > > > > > > > > After much searching online, still no hope in sight (the > trust level > > > cannot be overridden for this server) and some claim there is no > > > solution. > > > > > > (See > > > > > http://www.tisgoud.nl/blog/CommentView,guid,79cd746e-556a-4417 > > -a1fe-fb429bd3 > > > 7f80.aspx) > > > > > > > > > > > > Any ideas? Suggestions? > > > > > > > > > > > > I've tried loading configuration data from Global.asax (using > > > XmlConfigurator.Configure(),XmlConfigurator. > ConfigureAndWatch(.), > > > and the same for DOMConfigurator) and also using AssemblyInfo.cs > > > ([assembly: > > > > > > log4net.Config.XmlConfigurator(ConfigFile="log4net.config",Watch=true > > > )]), > > > you name it. > > > > > > > > > > > > Thanks in advance. > > > > > > > > > > > > Daniel > > > > > > > > > > > > --- > > > > > > Error message: > > > > > > > > > > > > Security Exception > > > > > > Description: The application attempted to perform an > operation not > > > allowed by the security policy. To grant this application the > > > required permission please contact your system administrator or > > > change the application's trust level in the configuration file. > > > > > > > > > > > > Exception Details: System.Security.SecurityException: > > Request for the > > > permission of type 'System.Configuration.ConfigurationPermission, > > > System.Configuration, Version=2.0.0.0, Culture=neutral, > > > PublicKeyToken=b03f5f7f11d50a3a' failed. > > > > > > > > > > > > Source Error: > > > > > > > > > > > > An unhandled exception was generated during the execution of the > > > current web request. Information regarding the origin and > location > > > of the exception can be identified using the exception > stack trace > > > below. > > > > > > > > > > > > Stack Trace: > > > > > > > > > > > > > > > > > > [SecurityException: Request for the permission of type > > > 'System.Configuration.ConfigurationPermission, > System.Configuration, > > > Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' > > > failed.] > > > > > > System.Security.CodeAccessSecurityEngine.Check(Object demand, > > > StackCrawlMark& stackMark, Boolean isPermSet) +0 > > > > > > System.Security.CodeAccessPermission.Demand() +59 > > > > > > > > > > > System.Configuration.BaseConfigurationRecord.CheckPermissionAl > > lowed(String > > > configKey, Boolean requirePermission, Boolean > isTrustedWithoutAptca) > > > +65 > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > -------------------------------------------------------------- > > -------------- > > > ---- > > > > > > Version Information: Microsoft .NET Framework > Version:2.0.50727.42; > > > ASP.NET > > > Version:2.0.50727.42 > > > > > > > > > > > >
