tag:blogger.com,1999:blog-563071785757928434.post1888644474542999225..comments2024-02-21T08:31:04.853+01:00Comments on Kodierer [Coder]: Silverlight Logging Extension MethodRene Schultehttp://www.blogger.com/profile/12777157871967896549noreply@blogger.comBlogger16125tag:blogger.com,1999:blog-563071785757928434.post-20287943090976716992016-04-29T08:48:40.538+02:002016-04-29T08:48:40.538+02:00What is it LogLevel ?
IMHO, I prefer if (!isCons...What is it LogLevel ?<br /><br />IMHO, I prefer if (!isConsoleAvailable) return;Kiquenethttps://www.blogger.com/profile/10446364197640116526noreply@blogger.comtag:blogger.com,1999:blog-563071785757928434.post-72906677934635342992015-02-26T15:52:23.084+01:002015-02-26T15:52:23.084+01:00Thanks for this, it worked for chrome and IEThanks for this, it worked for chrome and IEinsomniacThinkerhttps://www.blogger.com/profile/03194262056035805003noreply@blogger.comtag:blogger.com,1999:blog-563071785757928434.post-17742066870488332612015-02-26T15:51:16.557+01:002015-02-26T15:51:16.557+01:00works great! thanks! I tested in IE and Chrome bot...works great! thanks! I tested in IE and Chrome both worked fine!insomniacThinkerhttps://www.blogger.com/profile/03194262056035805003noreply@blogger.comtag:blogger.com,1999:blog-563071785757928434.post-2183537203140794992011-05-27T19:48:46.711+02:002011-05-27T19:48:46.711+02:00Really nice stuff. I am trying to use your logger ...Really nice stuff. I am trying to use your logger but it's working on IE9 but not on Chrome... By any chance, do you have a workaround to make it work on Chrome too? or at least make it fail silently on Chrome?<br /><br />Thanks a lot,<br />AlbinoAlbinohttp://intuitionlogic.comnoreply@blogger.comtag:blogger.com,1999:blog-563071785757928434.post-67045939060936485402011-02-10T15:09:44.654+01:002011-02-10T15:09:44.654+01:00I just wanted to share my workaround for the Chrom...I just wanted to share my workaround for the Chrome exception when Invoking console.log.<br /><br />My solution creates a user defined javascript function containing the call to console.log and passing the message as a parameter. I then call eval.call (window.execScript in IE) to load the function into global scope and then I can invoke my custom function instead of console.log directly. This works perfectly in Chrome.<br /><br />public void Log(LogLevel loglevel, string message)<br /> {<br /> if (loglevel <= level)<br /> {<br /> HtmlWindow window = HtmlPage.Window;<br /><br /> //only log if a console is available<br /> var isConsoleAvailable = (bool)window.Eval("typeof(console) != 'undefined' && typeof(console.log) != 'undefined'");<br /><br /> if (isConsoleAvailable)<br /> {<br /> var createLogFunction = (bool)window.Eval("typeof(ssplog) == 'undefined'");<br /> if (createLogFunction)<br /> {<br /> // Load the logging function into global scope:<br /> string logFunction = @"function ssplog(msg) { console.log(msg); }";<br /> string code = string.Format(@"if(window.execScript) {{ window.execScript('{0}'); }} else {{ eval.call(null, '{0}'); }}", logFunction);<br /> window.Eval(code);<br /> }<br /><br /> // Prepare the message<br /> DateTime dateTime = DateTime.Now;<br /> string output = string.Format("{0} - {1} - {2}", dateTime.ToString("u"), loglevel.ToString(), message);<br /><br /> // Invoke the logging function:<br /> var logger = window.Eval("ssplog") as ScriptObject;<br /> logger.InvokeSelf(output);<br /> }<br /> }<br /> }Anonymoushttps://www.blogger.com/profile/02346227836428477306noreply@blogger.comtag:blogger.com,1999:blog-563071785757928434.post-15475752528917522722010-09-30T12:15:23.365+02:002010-09-30T12:15:23.365+02:00Thanks a lot, that's a great info.
Just to no...Thanks a lot, that's a great info.<br /><br />Just to note that in case you are using Google Chrome without FireBug lite for chrome (which I just installed) the code is likely to crash during the consoleLogFunction.InvokeSelf, due to a System.InvalidOperationException exception.<br /> <br />You could do the Try/Catch trick to surround the call, unless there is a better test you could perform instead.<br />Vincent Thavonekham.thavohttps://www.blogger.com/profile/00070451538445834068noreply@blogger.comtag:blogger.com,1999:blog-563071785757928434.post-24585282193381642292010-09-30T11:38:59.097+02:002010-09-30T11:38:59.097+02:00This comment has been removed by the author.thavohttps://www.blogger.com/profile/00070451538445834068noreply@blogger.comtag:blogger.com,1999:blog-563071785757928434.post-33877158126622744252010-07-02T11:31:10.932+02:002010-07-02T11:31:10.932+02:00This comment has been removed by the author.jaranahttps://www.blogger.com/profile/12908136532791812458noreply@blogger.comtag:blogger.com,1999:blog-563071785757928434.post-42924381569315858272010-07-02T11:26:48.605+02:002010-07-02T11:26:48.605+02:00Hi Jarana,
sure, it's the Application.Current...Hi Jarana,<br /><br />sure, it's the Application.Current.RootVisual.Dispatcher<br /><br />Use it like this:<br />Application.Current.RootVisual.Dispatcher.BeginInvoke(() => "Log from another thread in the UI thread!".Log());Rene Schultehttps://www.blogger.com/profile/12777157871967896549noreply@blogger.comtag:blogger.com,1999:blog-563071785757928434.post-71272718557475860202010-07-02T11:09:39.458+02:002010-07-02T11:09:39.458+02:00It fails unless you call the Log method form the U...It fails unless you call the Log method form the UI thread. Any idea on how to retrieve the Dispatcher of the current Visual element?jaranahttps://www.blogger.com/profile/12908136532791812458noreply@blogger.comtag:blogger.com,1999:blog-563071785757928434.post-90222608574181294862010-06-14T17:53:43.429+02:002010-06-14T17:53:43.429+02:00It also works for Google Chrome if you install Fir...It also works for Google Chrome if you install FireBug lite for chrome.jaranahttps://www.blogger.com/profile/12908136532791812458noreply@blogger.comtag:blogger.com,1999:blog-563071785757928434.post-86326295268777247222010-03-25T17:14:53.532+01:002010-03-25T17:14:53.532+01:00HtmlPage.Window fails in none UI thread, so I call...HtmlPage.Window fails in none UI thread, so I call the above code from System.Windows.Deployment.Current.Dispatcher.BeginInvoke().SergeSnoreply@blogger.comtag:blogger.com,1999:blog-563071785757928434.post-74658682902140435562009-10-29T19:04:35.091+01:002009-10-29T19:04:35.091+01:00Where can you get System.Windows.Forms for silverl...Where can you get System.Windows.Forms for silverlight?Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-563071785757928434.post-59486131072425171432009-05-27T21:46:21.652+02:002009-05-27T21:46:21.652+02:00@Bill I totally missed that. Thanks for your comme...@Bill I totally missed that. Thanks for your comment! I updated the code snippet.Rene Schultehttps://www.blogger.com/profile/12777157871967896549noreply@blogger.comtag:blogger.com,1999:blog-563071785757928434.post-49360606200762845812009-05-27T16:54:05.151+02:002009-05-27T16:54:05.151+02:00Thanks for this tip! It really helped me out.
I ...Thanks for this tip! It really helped me out.<br /><br />I modified the code slightly to check for the existence of console and console.log. That way it will quietly fail (i.e., it won't throw an InvalidOperationException on Eval) if it's running in IE8 with the "Developer Tools" window closed or in earlier versions of IE.<br /><br />HtmlWindow window = HtmlPage.Window;<br />object hasConsole = window.Eval("typeof(console) != 'undefined' && typeof(console.log) != 'undefined'");<br />if (hasConsole is bool && (bool)hasConsole)<br />{<br /> ScriptObject consoleLogFunction = window.Eval("console.log") as ScriptObject;<br /> if (consoleLogFunction != null)<br /> {<br /> consoleLogFunction.InvokeSelf(entry);<br /> }<br />}Bill Meneeshttps://www.blogger.com/profile/00385302161839642783noreply@blogger.comtag:blogger.com,1999:blog-563071785757928434.post-76645855773719248482009-05-25T08:33:17.783+02:002009-05-25T08:33:17.783+02:00Nice tip! I might just use this. Thanks.Nice tip! I might just use this. Thanks.Jonathan van de Veenhttps://www.blogger.com/profile/15269789903353187250noreply@blogger.com