Try our conversational search powered by Generative AI!

Steve Celius
Mar 31, 2010
  12734
(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
From Procrastination to Proficiency: Navigating Your Journey to Web Experimentation Certification

Hey there, Optimizely enthusiasts!   Join me in celebrating a milestone – I'm officially a certified web experimentation expert! It's an exhilarati...

Silvio Pacitto | May 17, 2024

GPT-4o Now Available for Optimizely via the AI-Assistant plugin!

I am excited to announce that GPT-4o is now available for Optimizely users through the Epicweb AI-Assistant integration. This means you can leverag...

Luc Gosso (MVP) | May 17, 2024 | Syndicated blog

The downside of being too fast

Today when I was tracking down some changes, I came across this commit comment Who wrote this? Me, almost 5 years ago. I did have a chuckle in my...

Quan Mai | May 17, 2024 | Syndicated blog

Optimizely Forms: Safeguarding Your Data

With the rise of cyber threats and privacy concerns, safeguarding sensitive information has become a top priority for businesses across all...

K Khan | May 16, 2024

The Experimentation Process

This blog is part of the series -   Unlocking the Power of Experimentation: A Marketer's Insight. Welcome back, to another insightful journey into...

Holly Quilter | May 16, 2024

Azure AI Language – Sentiment Analysis in Optimizely CMS

In the following article, I showcase how sentiment analysis, which is part of the Azure AI Language service, can be used to detect the sentiment of...

Anil Patel | May 15, 2024 | Syndicated blog