Null "SecurityContext" reference in FileAppender
I am seeing an error when using the FileAppender with the BasicConfigurator. I get an exception when log4net tries to access the "SecurityContext" property, as it is null. I put together a quick console app to demonstrate the problem. Log4net debug output follows below. log4net version 1.2.9.0 .NET framework version 1.0.3705.6018 // BEGIN SAMPLE C# CONSOLE APP [STAThread] static void Main(string[] args) { string fileName = "C:\\log.txt"; log4net.Layout.PatternLayout layout = new log4net.Layout.PatternLayout("[%d] %-6p %-40c %-80m %l%n"); log4net.Util.LogLog.InternalDebugging = true; log4net.Appender.FileAppender fa = new log4net.Appender.FileAppender(); fa.File = fileName; fa.Layout = layout; log4net.Config.BasicConfigurator.Configure(fa); log4net.ILog log = log4net.LogManager.GetLogger("test"); log.Info("test message"); } // END SAMPLE C# CONSOLE APP // BEGIN LOG4NET DEBUG OUTPUT log4net: log4net assembly [log4net, Version=1.2.9.0, Culture=neutral, PublicKeyToken=null]. Loaded from [c:\vss\consoleapplication1\bin\debug\log4net.dll]. (.NET Runtime [1.0.3705.6018] on Microsoft Windows NT 5.0.2195.0) log4net: DefaultRepositorySelector: defaultRepositoryType [log4net.Repository.Hierarchy.Hierarchy] log4net: DefaultRepositorySelector: Creating repository for assembly [ConsoleApplication1, Version=1.0.1927.29103, Culture=neutral, PublicKeyToken=null] log4net: DefaultRepositorySelector: Assembly [ConsoleApplication1, Version=1.0.1927.29103, Culture=neutral, PublicKeyToken=null] Loaded From [c:\VSS\ConsoleApplication1\bin\Debug\ConsoleApplication1.exe] log4net: DefaultRepositorySelector: Assembly [ConsoleApplication1, Version=1.0.1927.29103, Culture=neutral, PublicKeyToken=null] does not have a RepositoryAttribute specified. log4net: DefaultRepositorySelector: Assembly [ConsoleApplication1, Version=1.0.1927.29103, Culture=neutral, PublicKeyToken=null] using repository [log4net-default-repository] and repository type [log4net.Repository.Hierarchy.Hierarchy] log4net: DefaultRepositorySelector: Creating repository [log4net-default-repository] using type [log4net.Repository.Hierarchy.Hierarchy] log4net:ERROR [FileAppender] OpenFile(C:\log.txt,True) call failed. System.NullReferenceException: Object reference not set to an instance of an object. at log4net.Appender.FileAppender.OpenFile(String fileName, Boolean append) in C:\Work\cvs_root\apache\r1.2.9\logging-log4net\build\package\log4net-1.2.9-beta\src\Appender\FileAppender.cs:line 982 at log4net.Appender.FileAppender.SafeOpenFile(String fileName, Boolean append) in C:\Work\cvs_root\apache\r1.2.9\logging-log4net\build\package\log4net-1.2.9-beta\src\Appender\FileAppender.cs:line 953 log4net:ERROR [FileAppender] No output stream or file set for the appender named []. // END LOG4NET DEBUG OUTPUT Comments: The error is occuring here- File: FileAppender.cs Method: virtual protected void OpenFile(string fileName, bool append) using(SecurityContext.Impersonate(this)) ... Line 982, the original exception source line (the "using" statement) is shown above.
RE: Help inserting GUID using AdoNetAppender
Have a look at the log4net.Layout.RawPropertyLayout class. I use that for my layout type, and still set the DbType to "Guid". I believe the log4net.Layout.RawPropertyLayout class was introduced in beta9, but you should be able to get it locally and incorporate it into your own build. At least that's what worked for me. ;) -Original Message- From: David Elliott [mailto:[EMAIL PROTECTED] Sent: Monday, April 11, 2005 1:43 PM To: log4net-user@logging.apache.org Subject: Help inserting GUID using AdoNetAppender I am trying to insert a uniqueidentifier (Guid) into a Sql Server table and am having problems. I'm using log4net-1.2.0-beta8. CREATE TABLE [dbo].[Log_Test1] ( [ID] [int] IDENTITY (1, 1) NOT NULL , [DateTime] [datetime] NOT NULL , [RequestID] [uniqueidentifier] NOT NULL , [TaskID] [tinyint] NOT NULL , [State] [tinyint] NOT NULL ) ON [PRIMARY] On startup of the application, I get the following error. log4net: DOMConfigurator: Setting Collection Property [AddParameter] to object [log4net.Appender.ADONetAppenderParameter] log4net: DOMConfigurator: Setting Property [ParameterName] to String value [EMAIL PROTECTED] log4net:ERROR DOMConfigurator: Could not create Appender [MyDBAppender] of type[log4net.Appender.AdoNetAppender]. Reported error follows. System.ArgumentException: Requested value uniqueidentifier was not found. at System.Enum.Parse(Type enumType, String value, Boolean ignoreCase) at log4net.helpers.OptionConverter.ParseEnum(Type enumType, String value, Boolean ignoreCase) at log4net.helpers.OptionConverter.ConvertStringTo(Type target, String txt) at log4net.Repository.Hierarchy.DOMHierarchyConfigurator.ConvertStringTo(Ty pe type, String value) at log4net.Repository.Hierarchy.DOMHierarchyConfigurator.SetParameter(XmlEl ement element, Object target) at log4net.Repository.Hierarchy.DOMHierarchyConfigurator.CreateObjectFromXm l(XmlElement element, Type defaultTargetType, Type typeConstraint) at log4net.Repository.Hierarchy.DOMHierarchyConfigurator.SetParameter(XmlEl ement element, Object target) at log4net.Repository.Hierarchy.DOMHierarchyConfigurator.ParseAppender(XmlE lement appenderElement) log4net:ERROR DOMConfigurator: Appender named [MyDBAppender] not found. If I change to Using "Guid" then it will load but then thrown an exception on insertion. log4net:ERROR [ADONetAppender] Exception while writing to database System.InvalidCastException: Invalid cast from System.String to System.Guid. at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream) at System.Data.SqlClient.SqlCommand.ExecuteNonQuery() at log4net.Appender.ADONetAppender.SendBuffer(IDbTransaction dbTran, LoggingEvent[] events) at log4net.Appender.ADONetAppender.SendBuffer(LoggingEvent[] events) Any thoughts would be appreciated. Dave _ Express yourself instantly with MSN Messenger! Download today - it's FREE! http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/
RE: Using v1.2.0 Beta 8 and v1.2.9 Beta at the same time?
Ron, My guess is that if you are in the same app domain, you could swap them in the /bin folder, but since there were breaking changes it might now work. You can't have them both there because there would be namespace conflicts. If they are in different app domains - such as two different asp.net apps, it shouldn't be a problem. -Original Message- From: Ron Grabowski [mailto:[EMAIL PROTECTED] Sent: Monday, April 11, 2005 9:26 AM To: log4net-user@logging.apache.org Subject: Using v1.2.0 Beta 8 and v1.2.9 Beta at the same time? I am using a component that is built against v1.2.0 Beta 8 of log4net.dll. The components ships with log4net.dll. If I want to use the new version of log4net in the code I write, is there an easy way for the two assemblies to co-exist?
Help inserting GUID using AdoNetAppender
I am trying to insert a uniqueidentifier (Guid) into a Sql Server table and am having problems. I'm using log4net-1.2.0-beta8. CREATE TABLE [dbo].[Log_Test1] ( [ID] [int] IDENTITY (1, 1) NOT NULL , [DateTime] [datetime] NOT NULL , [RequestID] [uniqueidentifier] NOT NULL , [TaskID] [tinyint] NOT NULL , [State] [tinyint] NOT NULL ) ON [PRIMARY] On startup of the application, I get the following error. log4net: DOMConfigurator: Setting Collection Property [AddParameter] to object [log4net.Appender.ADONetAppenderParameter] log4net: DOMConfigurator: Setting Property [ParameterName] to String value [EMAIL PROTECTED] log4net:ERROR DOMConfigurator: Could not create Appender [MyDBAppender] of type[log4net.Appender.AdoNetAppender]. Reported error follows. System.ArgumentException: Requested value uniqueidentifier was not found. at System.Enum.Parse(Type enumType, String value, Boolean ignoreCase) at log4net.helpers.OptionConverter.ParseEnum(Type enumType, String value, Boolean ignoreCase) at log4net.helpers.OptionConverter.ConvertStringTo(Type target, String txt) at log4net.Repository.Hierarchy.DOMHierarchyConfigurator.ConvertStringTo(Type type, String value) at log4net.Repository.Hierarchy.DOMHierarchyConfigurator.SetParameter(XmlElement element, Object target) at log4net.Repository.Hierarchy.DOMHierarchyConfigurator.CreateObjectFromXml(XmlElement element, Type defaultTargetType, Type typeConstraint) at log4net.Repository.Hierarchy.DOMHierarchyConfigurator.SetParameter(XmlElement element, Object target) at log4net.Repository.Hierarchy.DOMHierarchyConfigurator.ParseAppender(XmlElement appenderElement) log4net:ERROR DOMConfigurator: Appender named [MyDBAppender] not found. If I change to Using "Guid" then it will load but then thrown an exception on insertion. log4net:ERROR [ADONetAppender] Exception while writing to database System.InvalidCastException: Invalid cast from System.String to System.Guid. at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream) at System.Data.SqlClient.SqlCommand.ExecuteNonQuery() at log4net.Appender.ADONetAppender.SendBuffer(IDbTransaction dbTran, LoggingEvent[] events) at log4net.Appender.ADONetAppender.SendBuffer(LoggingEvent[] events) Any thoughts would be appreciated. Dave _ Express yourself instantly with MSN Messenger! Download today - it's FREE! http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/
Using v1.2.0 Beta 8 and v1.2.9 Beta at the same time?
I am using a component that is built against v1.2.0 Beta 8 of log4net.dll. The components ships with log4net.dll. If I want to use the new version of log4net in the code I write, is there an easy way for the two assemblies to co-exist?
OT - xml version 1.1 and XmlTextWrite/XmlTextReader
In http://issues.apache.org/jira/browse/LOG4NET-22, Nicko Cadell wrote: > The System.Xml.XmlTextWriter does not know which version XML is being > generated. When I did some testing on it, I found that neither (XmlTextWrite/XmlTextReader) handled . Is there actually a means for either to use XML Version 1.1? My work around was to use XML 1.0 with an ad-hoc mechanism to escape control characters. -- Mike Blake-Knox
RE: chainsaw and "escaping" XML entities
> >> For invalid characters such as 0x1e there are 3 possible solutions: > > >> 1) Discard the character from the output. > > >> 2) Replace the character with a numeric representation e.g. "0x1E". > > >> 3) Replace the character with an XML element e.g. > > > Nicko > > > >> favour option 3 above because information is not lost. In > options 1 > >> and 2 information is lost. In 2 the encoding is not > reversible. With > >> 3 the application reading the data requires additional smarts to > >> pickup on the encoded values in element, but all the original > >> information is preserved. If the app just asks for the > text nodes, > >> ignoring the child elements, then they will get back the > same result as from 1. > > If the application just deserializes the string, they'll end > up with a much more complex tree structure with a couple of > text nodes, an attribute node, If the app does a GetText on the message element they will get all the text nodes joined up without the sub elements, which is reasonable, i.e. just drop the control codes. If they use InnerXml then they get XML elements, but then they should expect that and live with it! > I don't see that the transport of binary data is a key > purpose for log4net. Much as I dislike option proliferation, Log4net should not be throwing away data, even if it is not very string like, just because XML doesn't like it. > I wonder if would it be reasonable to have 3 as an optional > behavior but 1 or 2 as a default? What does log4j do in this > situation? log4j's XMLLayout just writes to the output stream through a Writer so it does no escaping or numeric character reference encoding. It does write the message out into a CDATA section but that should not resolve the issue. I doubt that it works there either. Nicko > -- > Mike Blake-Knox >
Re: chainsaw and "escaping" XML entities
I hadn't realized the size of the can of worms I was opening. On Apr 10, 2005 3:07 PM, Nicko Cadell <[EMAIL PROTECTED]> wrote: > Mike, > > I have created an issue to track this. > > http://issues.apache.org/jira/browse/LOG4NET-22 > >> For invalid characters such as 0x1e there are 3 possible solutions: >> 1) Discard the character from the output. >> 2) Replace the character with a numeric representation e.g. "0x1E". >> 3) Replace the character with an XML element e.g. > Nicko > >> favour option 3 above because information is not lost. In options 1 and 2 >> information is lost. In 2 the encoding is not reversible. With 3 the >> application reading the data requires additional smarts to pickup on >> the encoded values in element, but all the original information is >> preserved. If the app just asks for the text nodes, ignoring the >> child elements, then they will get back the same result as from 1. If the application just deserializes the string, they'll end up with a much more complex tree structure with a couple of text nodes, an attribute node, I don't see that the transport of binary data is a key purpose for log4net. Much as I dislike option proliferation, I wonder if would it be reasonable to have 3 as an optional behavior but 1 or 2 as a default? What does log4j do in this situation? -- Mike Blake-Knox