Using Log4Net in ArcMap COM Extensions/Commands etc

Posted by Dave Bouwman | Posted in .NET, ArcGIS Devt, Utilities | Posted on 15-10-2009

6

I was building an edit task for ArcMap today, and got to a point where I had the geometry operations solid (using Test-Driven-Development for them) but when I got to iterating over sets of real data, I though it would be really handy to use a logger to kick out more detailed debug information. We use log4net in our web applications, so I thought I’d try dropping it in.

Turns out it took all of 5 minutes to get it working, so here’s the how-to (there’s some sample code at the end)

Get log4net

Get log4net from http://logging.apache.org/log4net/download.html – simple.

Add the Reference

Now that you have the log4net zip archive, copy the log4net.dll from the \log4net-1.2.10\bin\net\2.0\release folder in the zip file into your \lib folder. I always have a \lib folder for external assemblies that are used in a project. This is preferable to storing these in a central location because the \lib folder get’s stored in source control along with everything else that your project required. So – if you don’t have a lib folder, make one!

Now that it’s in the create a reference to log4net from your project in Visual Studio.

ref-log-for-net

Configure It

The easiest way to use log4net is with the standard log file appender which just writes to a text file. In order to configure this, we need to edit the ArcMap.exe.config file (located in \ArcGIS\bin). Of course you can store the log in other places (databases etc) – just Google for the details.

By default, this configuration file is almost empty, so you’ll need to add in the configSections as well as the log4net section.

<configSections>
  <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" 
       requirePermission="false" />
</configSections>

…lower down in the file…

<log4net>
  <appender name="LogFileAppender" type="log4net.Appender.FileAppender">
    <file value=".\\Logs\_log.txt" />
    <appendToFile value="true" />
    <lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
    <layout type="log4net.Layout.PatternLayout">
      <conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline%exception" />
    </layout>
  </appender>
  <root>
    <level value="ALL" />
    <appender-ref ref="LogFileAppender" />
  </root>
</log4net>

Now we have to wire log4net into our code. In order to be useful, we’ll want to have access to the “logger” throughout our class, so we’ll make it a private member. Ideally we’d pass in the logger from a dependency injection framework, but we’ll keep things simple for this example (sometimes DI *is* overkill). Thus, we’ll setup the logger in the constructor of our class.

private log4net.ILog _logger;

/// <summary>
///
Constructor.
/// </summary>
publicLRSEditTask()
{
    log4net.Config.XmlConfigurator.Configure();

_logger = log4net.LogManager.GetLogger(typeof(LRSEditTask));           
}

 

Logging

Would not be very much help if I did not show how to actually write to the log! Now that we have _logger, we can just pump data to it. There are a number of levels you use to send out data, depending on the severity. During development, I’ll use the Debug(<info>) method to see what’s going on inside the code, but you’ll also want to use the Warn, Error and Fatal methods when your code experiences errors. Using the different methods allows you to control what’s output to the log file via the configuration section. This way you can leave all that debug stuff in the code, but not have log files piling up on production systems.

In the sample code, I’m just pumping out examples of each type of log.

public void Activate(IEditor Editor, IEditTask oldTask)
{
    _logger.Info("Task Activated.");
}

public void Deactivate()
{
    _logger.Warn("Task Deactivated.");
}

public string Name
{
    get { return "Log4Net Example Task"; }
}

public void OnDeleteSketch()
{
    _logger.Fatal("On Delete Sketch Called");
}

public void OnFinishSketch()
{
    _logger.Error("On Finish Sketch Called");
}

 

In the log file you’ll see something like this…

2009-10-15 15:32:25,631 [1] INFO  Log4NetDemoTask.LogEditTask [(null)] – Task Activated.
2009-10-15 15:32:29,205 [1] ERROR Log4NetDemoTask.LogEditTask [(null)] – On Finish Sketch Called
2009-10-15 15:32:33,003 [1] FATAL Log4NetDemoTask.LogEditTask [(null)] – On Delete Sketch Called
2009-10-15 15:32:38,182 [1] WARN  Log4NetDemoTask.LogEditTask [(null)] – Task Deactivated.

Post Build Tasks

This is a subtle thing, but as far as I can tell, if you want your code to be able to “see” the ArcMap.exe.config file, your dll must reside in the \bin folder right beside ArcMap.exe. This is easily accomplished by adding a post-build event in Visual Studio

copy $(TargetDir)*.* “c:\program files\ArcGIS\bin”

Now, every time you build the project, it will copy your dll and any dependencies (log4net in our case) into the \bin folder.

A final note – when you start using logging, you’ll want to be able to look at the log without re-opening the file all the time. Thanks to Vish I’ve been using BareTail for quite some time now – this app will let you watch the file as lines are added to it.

Here’s a simple sample editing task, along with an ArcMap.exe.config file. Have fun!

Speaking at ESRI SWUG Next Week…

Posted by Dave Bouwman | Posted in Community, Conferences, ESRI, Presentations | Posted on 15-10-2009

3

swuglogo Just a quick note that I’ll be giving two talks next week at the ESRI South West Users Group (#SWUG09) meeting in Pueblo, Colorado. It will be nice to attend another conference that I don’t have to fly to!

I’ll be giving an updated talk on Usability as related to “GeoWeb” applications on Thursday  morning at 10:30am (Room “MR 4/5”). This will draw from some previous usability talks, but without the hard-core developer content, and more focus on the process of arriving at a usable application using ESRI technologies.

On Friday morning at 9:30am (also in room MR 4/5), I’ll be giving a talk for my usual accomplice, Brian Noyle (he got an elk tag, so he’ll be up in the mountains stalking large animals) that will also be about usability, but in the context of an emergency response application we built. I’ll go into the design decisions, the application architecture, and some of the complexities we ran into when building a highly configurable, high-security application that can consume remote map services. If you want to see how far you can push the ESRI Javascrip API, drop by.

Assuming the wireless is stable, we will also be streaming some of the sessions and hope to chat with people on GeoGeek.tv. At the very least, we’ll be recording my talks and hosting them somewhere.

I’ll also be tweeting about the various happenings using #SWUG09 as a hash tag, so you can follow along that way.

Hope to see you there!

GeoGeek.tv: Talkin Flex with Royce Simpson

Posted by Dave Bouwman | Posted in GeoGeekTV, Uncategorized | Posted on 08-10-2009

0

UPDATE: Apparently Royce has been slammed by the flu and will be re-scheduling – we’ll still talk Flex, and other random stuff though

Tomorrow, Oct 9th, we will be chatting with Royce Simpson, the developer who built the award winning City of Greeley “ORIGIN” mapping applications.

image

(Royce is on the right, Brian is on the left, and Jack is givin’ out the hugs)

We’ll talk about his background as a developer, what got him interested in Flex development, we’ll have him take us through the app and discuss various tools and how they were implemented.

Check out the apps, and join the chat to ask questions.

When: Oct 9, 2009 4:00pm MT

Where: http://geogeek.tv/live.aspx 

Follow Royce: @roycesimpson

Rethinking Conferences

Posted by Dave Bouwman | Posted in Community, Conferences | Posted on 06-10-2009

16

Over the last year I’ve been to many geo-conferences, and been privileged enough to speak at most of them. However, I think that there is something amiss in the current conference landscape. To quote Mark Frost in Fortune Magazine…

We’ve all been there: the dull business conference. A half-empty room of half-asleep attendees answer their e-mail on laptops and BlackBerries, while some hapless speaker lumbers through a PowerPoint speech.

How did we get here? I’ve been to somewhere between 50 and 75 geo-conferences over my career, and the dynamic has really changed. It used to be that people we pumped up to attend and were there to contribute and learn. Now it seems that attendees at most main-stream conferences are there to do one of three things:

a) market a product, or

b) present “project work”, or

c) avoid the office.

The rest clearly are not there to contribute, discuss or learn. This becomes blatantly clear when there are no questions at the end of a 90 minute session with 3 speakers. Really? Were you awake? Or maybe everyone is an expert in this niche (if so why is it on the agenda?) Or maybe no one cares about the topic (again, why is it on the agenda?)

That said, some geo-conferences still have a pulse, and I’m thinking of the ESRI Developer Summit and the WhereCamps in particular, but overall, the patient is on life support. What happened?

It’s the Economy Stupid!

While I’m sure that the economy has had a large effect on the overall number of people at any given event, it does not explain the general atmosphere in the sessions. Somehow I doubt the economy been particularly harsh on enthusiastic people. Or maybe organizations are simply sending the “dead wood” out of the office since they are not doing anything anyhow. Regardless, this is something that’s been going on for awhile now, and can’t just be blamed on Wall Street, so lets look at some other possibilities…

Marketing Overload

It seems that an awful lot of sessions are overt or very thinly veiled marketing – typically poorly executed. Some will argue that conferences must support the marketing angle because the sponsors defer a lot of the cost of the event, and thus they need some sort of platform to pitch their wares. However, anyone who’s read Seth Godin’s work knows that the era of “interruption marketing” (follow the link for a video) is on the way out. Pitching your next generation lossless geo-positioned cloud enabled, SOAP serviced, WMS-ified CAD/CAMA integration system to a room of people who don’t know what you are talking about, let alone need one, is a waste of time for all involved. Even if you manage to find the right niche session at the right niche conference, at least make it less “infomercial” and more “how this can help you help others”. Remember – these people did not come to hear a marketing pitch and they are used to Tivo – make them not want to fast-forward you.

If you have to do some marketing at a conference, my advice is simple – give people value: show them how to accomplish something, maybe using your widget/data/process for part of the solution, but offer other options as well. Be authentic. Be open. Be helpful. If you do this, you will connect, and in the end, that’s what you need to make a sale anyhow (unless you’re pitching ShamWow! in which case, stick with the infomercials, and us Tivo owners will never hear you again)

The “Project” Presentation

This should be the meat of most “non-vendor” conferences. We’re here to hear about how our peers are using their skills to make the world a better place. The bizarre thing is that these are usually done like a 3rd grader doing their first “What I did on Summer Vacation” assignment. Reading a bullet list of the ESRI products you used in the production of the city bike lane map is just as boring and useless as it sounds.

Tell us why you did the project and what great things resulted (fewer accidents, better quality of life, lower air pollution). If you did some really awesome stuff integrating systems (and I’m talking about importing an Excel file), tell us both the HOW and the WHY. Context is important. I’ve seen plenty of talks about “boring” topics which were riveting, and many talks on “inspirational” topics killed by someone reading their slideument to a crowd.

Since most people rank public speaking as their #1 fear, here are some useful books – Slide:ology by Nancy Duarte and Presentation Zen by Garr Reynolds. Although commonly cited as resources for good slide design, both books discuss the importance of having a story, the delivery and how to connect with the audience. Anyone presenting at any conference should read these books And if you’re not a natural loud mouth public speaker, they are invaluable. If you need to do a lot of speaking, I’ve heard good things about Toast Masters. And to show you that anyone – even a 5th grader – can give an awesome talk, watch this YouTube video and start re-thinking how you’re going to do things.

Above all – come prepared. I saw one presentation this last year where the speaker ran into the room about a minute before the talk was to start, and clearly had  not even run through her slides before. Sure, expectations are lower than for a TED talk (more on this later), but do us all the respect to bring at least your “B” game, or cancel. Watching someone flounder on stage is horrible (especially if you are not near a door).

Office Avoidance

These are the worst attendees. And what really baffles me is that if you are going to sleep through every session, WHY BOTHER? Just head out to the local attractions, and roll in later in the day for the social events. Having half a room nodding off (partly due to poor presentations) really kills any energy there may have been. So – if you are just avoiding the office, do us all a favor and avoid the sessions as well.

Moving Forward…

I’m not saying I have the definitive answer to the problems outlined above, but here are some ideas. Ideally this will become a conversation and we can set new expectations and chart a new course for our industry. Leave some comments here, or better – write a blog post of your own! Tweet this! Do whatever it takes to get others to think about this because if we all sit back, nothing will change. Let’s be honest – conferences live and die by attendance. Since we can vote with our feet, this is one area where the community has almost absolute power – lets exercise it!

Maybe Less is More?

First, why not scale things back? Who needs 100 conferences each with 10 tracks trying to cover every niche? This makes it more difficult to find great speakers and necessitates huge facilities. What if there were one-half or one-third the number of conferences, and just one or two big rooms at each? And only the most compelling presenters, talking about the most pertinent topics were given a slot on the stage? What if there was more time to actually talk to the speakers or the other people?

Taking a cue from TED

This is the key idea behind the TED Conference. TED started in 1984, and the idea was simple – lets get the best people from the Technology, Entertainment and Design industries together to share ideas. Now, these people are extreme. The cost for the 2010 Long Beach conference is a shocking $6000 a seat (already sold out in case you were wondering). Due to it’s popularity, they are adding a “remote” location called “TEDActive” in Palm Springs, where you can get a seat to watch the streamed coverage for a mere $3750. Not only that, you need to apply to attend – there are essay questions on the registration form (more info here). What’s awesome is that there is ONE conference, with the most kick-ass people across a wide-range of fields attending, and only the most amazing presenters are invited to talk. And even then, they only get between 6 and 15 minutes. Now, you may think that this is just some uber rich event like Davos, but check out these presentations by Hans Rosling, Jill Bolte-Tayor and Josh Silver and get back to me. These are amazing presenters, telling compelling stories about what they are doing, and how they are trying to change the world.

Ok, so TED takes this to an extreme, but right now the geo-conference circuit is so packed with events that we are at the opposite end of the spectrum. There are easily a dozen events a month just in the US. These range from the large events like GEOINT and FOSS4G to smaller events like the Texas GIS Forum or GeoWeb. Every one of these events is vying for and audience and presenters. Maybe cutting things down a little would help a lot? Maybe everyone could bring their “A” game, and we could actually work on solving some real problems? (wasn’t that what got most of us into GIS in the first place??)

It’s about Participation

One way to combat the nodding heads is to keep them involved from planning to the closing. Even at vendor conferences focused on technology transfer (ESRI Dev Summit, Microsoft TechEd & PDC etc.) involving the audience in the planning can have a huge impact. Face it – people are spending a lot of time and money to attend these things, so the more control they have over what they will get out of the event the better.

Conference Planning

The traditional model of peer reviewed conferences, where presenters had to submit a “real” paper, which was then reviewed and published in proceedings is now long gone. Although there are a few “GIS Journals” hanging on, they are a dying breed, and the “abstract” requirement at most conferences is only a formality and a nod to history. The reality is that the “abstract” is really just the elevator pitch. And I commend this – with a bunch of simultaneous sessions, I’m more likely to got to the one with the catchy description simply because the presenter may actually be excited about what they are talking about!

Nonetheless, the abstracts are mostly still selected by a panel, and this has some flaws. The first is transparency -  the people involved in setting up conferences are usually also involved in the industry the conference serves, and thus have some vested interest in particular views. This is not always the case, as evidenced by the GeoWeb conference, which is run by Ron Lake (the father of GML) and Galdos. They had multiple sessions featuring speakers such as Andrew Turner and James Fee who are decidedly not GML apostles.

At the other end of the spectrum here, we have the “un-conference” where sessions are determined on the fly based on who shows up. While this is a really cool model, I suspect (correct me if I’m wrong) there are issues scaling it up and down. There’s likely a critical mass where it works really well, but I can’t see 2000 people coming to a consensus on technical sessions in any rapid manner. And if there are less than 50 participants, finding enough common interests can make things difficult (try being a .NET Developer at a WhereCamp!). In order to convince large numbers of people to spend money and travel, more pre-planned structure is needed. All that said, it looks like this is exactly what the ReadWrite “Real-Time” Web Summit is set to do next week, so maybe we’ll get a sense of how well that works.

Personally, I think something like the SXSW’s “panel picker” can play a huge role. In their system, the audience gets a 30% weighting in the acceptance formula. This sort of a system would help weed out a great many of presentations that people are not interested in, at the same time getting prospective attendees excited about attending.

On-site involvement is also critical. At some conferences, the organizers are now acknowledging the “back channel” by projecting IRC or Twitter streams onto a screen in the room. Since the back channel is going to happen (at any reasonably tech-savvy conference), surfacing it and making it part of the experience is a huge step in audience involvement. Sure, there are risks, like some of the panels at SXSW where the twitter back-channel took on a life of it’s own, but if nothing else it shows that the audience does have an agenda, expectations and since they are already empowered, you may as well work with them instead of against them. I’ll commend ESRI for jumping into the interactive social media pool in a big way following this year’s Dev Summit. Now we just need to get more of the average ESRI Developers/Users on twitter, but that’s a totally different blog post…

External Involvement

Once you accept that the back channel is there, and is public, why not simply stream the sessions? On-site participation will always be a premium because of the face-to-face networking opportunities, but why not chose venues that have solid network infrastructure so that the sessions can be streamed live? This goes back the the idea of smaller facilities – which may actually have better connections! Both WhereCamp5280 and GeoWeb 2009 were at university facilities that had great internet connections. If I can use a $50 webcam and free UStream.TV to broadcast from these events, it’s clear to me that this can be done by any conference. Streaming is not going to cannibalize the on-site audience – those people were not going to come anyhow, but you can enable them to become part of the conversation anyhow. If there is a huge on-line presence for a conference, I would expect that would improve the “brand” of the conference, and I’d bet that it will increase attendees in following years. It also shows that you genuinely care about the community you service. Times are tough, so fewer people can afford to attend, but streaming the sessions enables content to be distributed anyhow. I would hope that large vendor events such at the ESRI conferences would move to this model, but the facilities they host the events at have notoriously poor internet connections. At least they to post the session videos after the fact.

Who’s Leading?

Carsonified hosts a series of events each year – mostly in the UK, but they also have some US dates. While not “geo” specific, these conferences (Future of Web Apps, Future of Web Design, Future of Mobile) are based around the "one big room” model. They get great presenters, stick them in a room with an audience and film everything. You can browse the archives or jump right to a fully caffeinated Andrew Turner talking about “Beyond Google Maps” from 2008. What’s awesome is that the web site that archives the content is a first class citizen in the Carsonified world. There’s the video of the talk, the slides, a highlight reel and sometimes an interview after the talk. Combined with the rich tagging and comment capability, this is an awesome improvement over the current conference web-site model.

However, the <head> conference sounded like a good model for next generation conferences…

<head> is a web conference with all of the traditional elements. We have live speakers, presentations, question and answer sections, and networking opportunities. The twist is that the conference takes place everywhere — all over the world — and at real-world gatherings called local conference hubs.

Live presentations, streamed to local “hubs” all tied in through the internet! Talk about upside for everyone involved – people don’t have to travel long distances, yet the social aspect is still covered by having the local in-person venues! And talk about “Green” – way fewer flights were required, less rental cars and all that hotel laundry!

Who loses in this model? Lets see… those over priced hotels that charge $12.95 per day for unstable wireless, and the airlines. Boohoo.

It does not look like there was a follow up planned for 2009, but I could see this sort of thing changing the game significantly in years to come.

Call to Action!

In this era of cost containment, conference attendees really need to see more value. I’d wager that expenses to send a person to a 4 day conference run between $1000 and $1500. Add in their salary, and the opportunity cost (not having them do the work they are paid for) and you can easily hit $3000 to $5000. Multiply that by 500 or a 1000 attendees and you’re looking at a huge investment pool. The question is: What value are we all getting for that investment?

Right now, the return is pretty poor for most conferences. Between the marketing and the PowerPoint hell, it’s hard to make the case to attend. If they intend to remain part of the landscape, geo-conferences simply have to change. WhereCamps are showing that if the geo-conference community does not get on board, the user community will simply evolve – on it’s own. There are successful models out there, we just need to demand quality and vote with our feet!

Feedback:

I would hope that this post generates discussions around the geo-community, and perhaps some conference organizers might be interested in having a chat. So, if you’ve got some ideas, peeves, or gripes, leave some comments with your thoughts, and I’ll pass them on.

  • What would you change about the last conference you attended?
  • What would you most like to see in future events?
  • Could you attend more conferences if the travel was local (i.e. within 50 miles)?
  • Could you attend more conferences if they had a “real” on-line option (possibly involving some $$)