Don't miss out Virtual Happy Hour today (April 26).

Try our conversational search powered by Generative AI!

Steve Celius
Mar 31, 2010
  12716
(0 votes)

log4net tips: Shortening the type name

If you’re using an appender layout like this:

   1: <layout type="log4net.Layout.PatternLayout">
   2:     <conversionPattern value="%date %level [%thread] %type.%method - %message%n" />
   3: </layout>

The conversion pattern is:

%date %level [%thread] %type.%method - %message%n

Which is the default one for the fileLogAppender shipping with EPiServer (note that type & method logging is slow, but immensely useful when you need it.)

A log line could look like this:

2009-12-09 17:27:04,655 INFO [6] Microsoft.Samples.Runtime.Remoting.Channels.Pipe.PipeConnection.Write - 18.3.1 Scheduler info:  2780> Write string Content-Type

The whole type name is included. In most cases, you just need the name of the class and method, which will save you some logging space (more on that later), but it will also make your log easier to read.

The %type pattern supports this syntax: %type{n} where <n> is the number of class/namespaces to include (from the right).

Changing the pattern to:

%date %level [%thread] %type{1}.%method - %message%n

yields the following log:
2009-12-09 17:27:04,655 INFO [6] PipeConnection.Write - 18.3.1 Scheduler info:  2780> Write string Content-Type

Read more about this in the log4net SDK documentation on the PatternLayout class.

Mar 31, 2010

Comments

Please login to comment.
Latest blogs
Optimizely Unit Testing Using CmsContentScaffolding Package

Introduction Unit tests shouldn't be created just for business logic, but also for the content and rules defined for content creation (available...

MilosR | Apr 26, 2024

Solving the mystery of high memory usage

Sometimes, my work is easy, the problem could be resolved with one look (when I’m lucky enough to look at where it needs to be looked, just like th...

Quan Mai | Apr 22, 2024 | Syndicated blog

Search & Navigation reporting improvements

From version 16.1.0 there are some updates on the statistics pages: Add pagination to search phrase list Allows choosing a custom date range to get...

Phong | Apr 22, 2024

Optimizely and the never-ending story of the missing globe!

I've worked with Optimizely CMS for 14 years, and there are two things I'm obsessed with: Link validation and the globe that keeps disappearing on...

Tomas Hensrud Gulla | Apr 18, 2024 | Syndicated blog

Visitor Groups Usage Report For Optimizely CMS 12

This add-on offers detailed information on how visitor groups are used and how effective they are within Optimizely CMS. Editors can monitor and...

Adnan Zameer | Apr 18, 2024 | Syndicated blog

Azure AI Language – Abstractive Summarisation in Optimizely CMS

In this article, I show how the abstraction summarisation feature provided by the Azure AI Language platform, can be used within Optimizely CMS to...

Anil Patel | Apr 18, 2024 | Syndicated blog