---
title: "How to get class name?"  
description: "How to get class name?"  
author: "Lillian Martin"  
published: 2015-01-18  
updated: 2015-01-18  
canonical: https://www.mindstick.com/forum/12871/how-to-get-class-name  
category: "asp.net"  
tags: ["c#", ".net", "reflection"]  
reading_time: 1 minute  

---

# How to get class name?

How to get the [class](https://www.mindstick.com/blog/165/generic-class-in-c-sharp)-name with caller [info](https://answers.mindstick.com/qa/93284/what-can-we-write-in-about-us-column-in-basic-info-profile) [attributes](https://www.mindstick.com/articles/13105/2-attributes-that-make-your-odoo-ecommerce-theme-productive-and-engaging).

I strongly [say](https://answers.mindstick.com/qa/116645/a1-wreckers-reviews-what-do-customers-say) a no to [log](https://www.mindstick.com/articles/126269/the-main-uses-of-log-cabins) the class name using reflection.

Was able to get the [method name](https://www.mindstick.com/forum/33583/selector-creation-with-method-name-and-parameter) using the [[CallerMemberName](https://www.mindstick.com/interview/34288/what-is-the-purpose-of-callermembername-callerfilepath-and-callerlinenumber)] like below:

```
        private void Log(string logMessage, [CallerMemberName]string callerName = null)        {            if (logger.IsDebugEnabled)            {                logger.DebugFormat("Executing
Method = {1};{0}", logMessage, callerName);            }        }
```

How to log the class name here using **Caller Info Attributes** ?

## Replies

### Reply by Anurag Sharma

You can't there is no attribute available that does that. However because Log is private no external classes could call the function so you already know which class called it.

```
public SomeClass{     //(snip)     private void Log(string logMessage, [CallerMemberName]string callerName = null)    {         if (logger.IsDebugEnabled)        {            string className = typeof(SomeClass).Name;             logger.DebugFormat("Executing Method = {1};{2}.{0}", logMessage, callerName, className);        }    }}
```


---

Original Source: https://www.mindstick.com/forum/12871/how-to-get-class-name

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
