Monday, October 19, 2009
WPF and the modal dialog (boring)
Warning boring tech related blog entry follows:
The trick (hack) is the following
1) You need a System.IntPtr containing a pointer to the windows handle (this.Handle if you are lucky enough to be in a System.Windows.Window.Form)
2) You need to feed this pointer into your dialog thusly:
WindowInteropHelper wih = new WindowInteropHelper(myUserControl);
wuh.Owner = myIntPtr;
// then, with magical flair:
myUserControl.ShowDialog();
Labels: boring, c#, code, geek, net
Tuesday, October 13, 2009
log4net
I keep forgetting how to switch on log4net (using app.config)
I always end up wasting time on the apache docs, and searching the net to find this
Step 1: Edit AssemblyInfo.cs
[assembly: log4net.Config.XmlConfigurator(Watch = true)]
Step 2: Edit App.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
</configSections>
<log4net>
<appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender" >
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger [%ndc] - %message%newline" />
</layout>
</appender>
<root>
<level value="INFO" />
<appender-ref ref="ConsoleAppender" />
</root>
</log4net>
</configuration>
I always end up wasting time on the apache docs, and searching the net to find this
Step 0:
Ensure that the first declaration of
"private static readonly log4net.ILog Log =log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);"
Occurs in your main assembly - if the first declaration is in linked assemblies, it won't load the setting correctly.
Step 1: Edit AssemblyInfo.cs
[assembly: log4net.Config.XmlConfigurator(Watch = true)]
Step 2: Edit App.config
Important! The configSections bit has to be at the top of your config file. So if you've got an existing one, don't just add it on to the end!
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
</configSections>
<log4net>
<appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender" >
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger [%ndc] - %message%newline" />
</layout>
</appender>
<root>
<level value="INFO" />
<appender-ref ref="ConsoleAppender" />
</root>
</log4net>
</configuration>
Step 3:
Need more example files - go to http://logging.apache.org/log4net/release/config-examples.html
Labels: .net, coding, log4net, programming