From: Stephen B. <sb...@gm...> - 2012-12-14 15:31:48
|
If that's really where it originates, then it would appear the trouble is the presence of { } characters in the call to string.Format(...), is that right? If that's the case, then the only real way I see to correct this would be to ensure that { } are properly escaped in the input to string.Format(...). I'm not sure there is a 'workaround' in the sense of something that wouldn't require a change in the underlying Common.Logging code itself -- any solution would probably mean changing code and releasing a new version of Common.Logging (if I'm properly understanding your description of the issue). I *do* completely agree that arbitrarily-embedded { } chars should be supported as literals in the message-being-logged (since as you point out you're not always in complete control of the message content) so I'd think we'd want to make exactly that kind of a change (e.g., pre-process incoming messages by passing them through a function that would do a simple substitution of "This is a message with { and } in it." to something more like "This is a message with \{ and \} in it." We'd be happy to review a pull request if you want to fork the repo and propose a fix; else we can obviously put this (relatively) high in the backlog for the existing contributors as well. If you want to take a stab at proposing a fix, please let us know and we'll avoid pursuing it directly ourselves pending your pull request. Thanks for your help in isolating the issue~! Cheers, -Steve B. Steve Bohlen sb...@gm... http://blog.unhandled-exceptions.com http://twitter.com/sbohlen On Fri, Dec 14, 2012 at 10:13 AM, Peter Kirk <pk...@al...> wrote: > Thanks. I have done that. > > I have also looked into the common-logging source, and I think I see where > and why the error occurs. > It appears it stems from class AbsractLogger, in the method: > > private string FormatMessage(string format, params object[] args) > { > cachedMessage = string.Format(formatProvider, format, args); > return cachedMessage; > } > > Where obviously any { } is interpreted as format parameters. > > Any ideas to a good workaround? I sometimes want to log strings which > originate elsewhere, and which may contain { }. And I "always" use the > lambda expression call to common-logging, as I find it extremely useful. > > Thanks, > Peter > > > > From: Stephen Bohlen [mailto:sb...@gm...] > Sent: 14. december 2012 15:56 > To: Peter Kirk > Cc: net...@li... > Subject: Re: [Netcommon-developer] Common.Logging: : Input string was not > in a correct format > > Hmm...I have to agree that sounds like a Common.Logging issue after all -- > thanks for your help in trying to better isolate the problem. Can you open > an issue here > https://github.com/net-commons/common-logging/issues?state=open and we'll > try to look into it for you soon --? > > Thanks again, > > -Steve B. > > > Steve Bohlen > sb...@gm... > http://blog.unhandled-exceptions.com > http://twitter.com/sbohlen > > > On Fri, Dec 14, 2012 at 9:47 AM, Peter Kirk <pk...@al...> wrote: > Hi - thanks for your reply. > > If I try the following, then the failure occurs when passing the lambda > expression to common.logging. > So log4net itself, and the non-lambda call to common-logging work fine. > But when trying to pass the lambda, common-logging doesn't like it. > > log4net.Config.XmlConfigurator.Configure(new FileInfo("log4net.config")); > log4net.ILog log4netLog = log4net.LogManager.GetLogger("TestApp"); > > Common.Logging.ILog commonLog = > Common.Logging.LogManager.GetCurrentClassLogger(); > > log4netLog.Debug("log4net {a}"); > commonLog.Debug("common logging {a}"); > commonLog.Debug(m => m("common logging lambda {a}")); > > > /Peter > > > From: Stephen Bohlen [mailto:sb...@gm...] > Sent: 14. december 2012 14:40 > To: Peter Kirk > Cc: net...@li... > Subject: Re: [Netcommon-developer] Common.Logging: : Input string was not > in a correct format > > I am nearly certain that this issue is coming from Log4Net rather than > Common.Logging. Assuming this email contains your full stack trace, you > can see this too by noting the root exception seems to originate from > log4net.ObjectRenderer.RendererMap.FindAndRender(Object obj, TextWriter > writer). > > IIRC in Log4Net the { } characters are used as replacement tokens in log > message formatting strings and so are probably either reserved entirely or > need to be escaped. Common.Logging isn't doing any 'processing' of the log > messages, merely passing them off to whatever logging framework you're > using so I'd start there. The simplest way to confirm this would probably > be to try to wire up log4net to a test class of your own and forcibly try > to process a log message like... > > log.Debug(m => m("this is a test with some { and } characters")); > > ...and see if log4net can handle that 'natively' using your same log4net > configuration/logging format settings. > > Let us know if this helps~! > > -Steve B. > > > Steve Bohlen > sb...@gm... > http://blog.unhandled-exceptions.com > http://twitter.com/sbohlen > > On Fri, Dec 14, 2012 at 5:13 AM, Peter Kirk <pk...@al...> wrote: > Hi, I am using common.logging (with log4net 1.2.10). Sometimes, when I try > to log a string which I received from an external service, the logging > system throws an exception. I am not sure if the exception originates from > common.logging or log4net. > > For example, I do: > string s = service.GetName(); > log.Debug(m => m("servicename=" + s)); > > It appears this exception occurs because the string contains '{' and/or > '}' characters. Can this be correct? (Maybe the name I get is > "Service81{loc17}"). > > <log4net.Error>Exception rendering object type > [Common.Logging.Factory.AbstractLogger+FormatMessageCallbackFormattedMessage]<stackTrace>System.FormatException: > Input string was not in a correct format. > at System.Text.StringBuilder.AppendFormat(IFormatProvider provider, > String format, Object[] args) > at System.String.Format(IFormatProvider provider, String format, > Object[] args) > at > Common.Logging.Factory.AbstractLogger.FormatMessageCallbackFormattedMessage.FormatMessage(String > format, Object[] args) > at > Alpha.Portal.ServiceAccess.Search.<>c__DisplayClass6.<AllContent>b__5(FormatMessageHandler > m) > at > Common.Logging.Factory.AbstractLogger.FormatMessageCallbackFormattedMessage.ToString() > at log4net.ObjectRenderer.DefaultRenderer.RenderObject(RendererMap > rendererMap, Object obj, TextWriter writer) > at log4net.ObjectRenderer.RendererMap.FindAndRender(Object obj, > TextWriter writer)</stackTrace></log4net.Error> > > Thanks for any comments, > Peter > > > ------------------------------------------------------------------------------ > LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial > Remotely access PCs and mobile devices and provide instant support > Improve your efficiency, and focus on delivering more value-add services > Discover what IT Professionals Know. Rescue delivers > http://p.sf.net/sfu/logmein_12329d2d > _______________________________________________ > Netcommon-developer mailing list > Net...@li... > https://lists.sourceforge.net/lists/listinfo/netcommon-developer > > > > |