Try our conversational search powered by Generative AI!

Steve Celius
Mar 31, 2010
  12717
(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
Azure AI Language – Extractive Summarisation in Optimizely CMS

In this article, I demonstrate how extractive summarisation, provided by the Azure AI Language platform, can be leveraged to produce a set of summa...

Anil Patel | Apr 26, 2024 | Syndicated blog

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