duplicate log entries Nlog
up vote
1
down vote
favorite
I use Nlog to log and i find that i have 5 entries in my log file for every call made to nLog. How can i fix it?
for eg.
2012-12-23 18:18:19.2465 NinjaTrader.Strategy.LODHOD.OnStartUp Debug startup
2012-12-23 18:18:19.2465 NinjaTrader.Strategy.LODHOD.OnStartUp Debug startup
2012-12-23 18:18:19.2465 NinjaTrader.Strategy.LODHOD.OnStartUp Debug startup
2012-12-23 18:18:19.2465 NinjaTrader.Strategy.LODHOD.OnStartUp Debug startup
2012-12-23 18:18:19.2465 NinjaTrader.Strategy.LODHOD.OnStartUp Debug startup
2012-12-23 18:18:19.2465 NinjaTrader.Strategy.LODHOD.OnStartUp Debug startup
My nLog config is as below
/****CLASS LEVEL VARIABLES***/
// Step 1. Create configuration object
private static LoggingConfiguration config = new LoggingConfiguration();
private static FileTarget fileTarget = new FileTarget();
private static Logger logger = LogManager.GetCurrentClassLogger();
/*** END OF CLASS LEVEL VARIABLES ***/
/*************************NLOG CONFIG*****/
fileTarget.FileName =
"C:\temp\" + Instrument.FullName + "nLog." + DateTime.Now.Ticks + ".log";
fileTarget.Layout =
"${longdate} ${callsite} ${level} ${event-context:item=StrategyId} ${message}";
config.AddTarget("file", fileTarget);
// Step 4. Define rules
LoggingRule rule2 = new LoggingRule("*", NLog.LogLevel.Trace, fileTarget);
config.LoggingRules.Add(rule2);
// Step 5. Activate the configuration
LogManager.Configuration = config;
logger.Debug("startup");
/*************************NLOG CONFIG*****/
you can see the starup printed 6 times and it is called only once in the program at the begining of the program in the Ninjatrader onStartup.
I also have the scoped Global Diagnistoc but i dont think that can cause this to happen
public class ScopedGlobalContext : IDisposable
{
private string n;
private string v;
public ScopedGlobalContext(string name, string value)
{
n = name;
v = value;
NLog.GlobalDiagnosticsContext.Set(n, v);
}
public void Dispose()
{
NLog.GlobalDiagnosticsContext.Remove(n);
}
}
logging nlog
|
show 3 more comments
up vote
1
down vote
favorite
I use Nlog to log and i find that i have 5 entries in my log file for every call made to nLog. How can i fix it?
for eg.
2012-12-23 18:18:19.2465 NinjaTrader.Strategy.LODHOD.OnStartUp Debug startup
2012-12-23 18:18:19.2465 NinjaTrader.Strategy.LODHOD.OnStartUp Debug startup
2012-12-23 18:18:19.2465 NinjaTrader.Strategy.LODHOD.OnStartUp Debug startup
2012-12-23 18:18:19.2465 NinjaTrader.Strategy.LODHOD.OnStartUp Debug startup
2012-12-23 18:18:19.2465 NinjaTrader.Strategy.LODHOD.OnStartUp Debug startup
2012-12-23 18:18:19.2465 NinjaTrader.Strategy.LODHOD.OnStartUp Debug startup
My nLog config is as below
/****CLASS LEVEL VARIABLES***/
// Step 1. Create configuration object
private static LoggingConfiguration config = new LoggingConfiguration();
private static FileTarget fileTarget = new FileTarget();
private static Logger logger = LogManager.GetCurrentClassLogger();
/*** END OF CLASS LEVEL VARIABLES ***/
/*************************NLOG CONFIG*****/
fileTarget.FileName =
"C:\temp\" + Instrument.FullName + "nLog." + DateTime.Now.Ticks + ".log";
fileTarget.Layout =
"${longdate} ${callsite} ${level} ${event-context:item=StrategyId} ${message}";
config.AddTarget("file", fileTarget);
// Step 4. Define rules
LoggingRule rule2 = new LoggingRule("*", NLog.LogLevel.Trace, fileTarget);
config.LoggingRules.Add(rule2);
// Step 5. Activate the configuration
LogManager.Configuration = config;
logger.Debug("startup");
/*************************NLOG CONFIG*****/
you can see the starup printed 6 times and it is called only once in the program at the begining of the program in the Ninjatrader onStartup.
I also have the scoped Global Diagnistoc but i dont think that can cause this to happen
public class ScopedGlobalContext : IDisposable
{
private string n;
private string v;
public ScopedGlobalContext(string name, string value)
{
n = name;
v = value;
NLog.GlobalDiagnosticsContext.Set(n, v);
}
public void Dispose()
{
NLog.GlobalDiagnosticsContext.Remove(n);
}
}
logging nlog
As your rule is called rule2, do you have multiple ones?
– ccellar
Dec 25 '12 at 10:34
no. that is all the code that i have for nLog. i deleted the rule1 but forgot to rename the variables. I am still not sure why it gets printed 6 times
– junkone
Dec 26 '12 at 21:21
Do you have any NLog configuration, either in app.config or in NLog.config? Have you posted all of your NLog configuration code? I see you have a variable, "config", where does it come from?
– wageoghe
Dec 28 '12 at 19:47
these are just class level variables that i was using. i cut and pasted it in the code sample that i have shown.
– junkone
Dec 29 '12 at 20:59
1
In the first code block you have a section (as noted in the comments) called "CLASS LEVEL VARIABLES". Do you have this same code in each class? I ask this because, you should configure NLog exactly once in your application, not once per class. Have you tried making a stripped down program/library to experiment with NLog? It might be easier to figure out what is going on with NLog if you have less stuff going on.
– wageoghe
Jan 2 '13 at 18:06
|
show 3 more comments
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I use Nlog to log and i find that i have 5 entries in my log file for every call made to nLog. How can i fix it?
for eg.
2012-12-23 18:18:19.2465 NinjaTrader.Strategy.LODHOD.OnStartUp Debug startup
2012-12-23 18:18:19.2465 NinjaTrader.Strategy.LODHOD.OnStartUp Debug startup
2012-12-23 18:18:19.2465 NinjaTrader.Strategy.LODHOD.OnStartUp Debug startup
2012-12-23 18:18:19.2465 NinjaTrader.Strategy.LODHOD.OnStartUp Debug startup
2012-12-23 18:18:19.2465 NinjaTrader.Strategy.LODHOD.OnStartUp Debug startup
2012-12-23 18:18:19.2465 NinjaTrader.Strategy.LODHOD.OnStartUp Debug startup
My nLog config is as below
/****CLASS LEVEL VARIABLES***/
// Step 1. Create configuration object
private static LoggingConfiguration config = new LoggingConfiguration();
private static FileTarget fileTarget = new FileTarget();
private static Logger logger = LogManager.GetCurrentClassLogger();
/*** END OF CLASS LEVEL VARIABLES ***/
/*************************NLOG CONFIG*****/
fileTarget.FileName =
"C:\temp\" + Instrument.FullName + "nLog." + DateTime.Now.Ticks + ".log";
fileTarget.Layout =
"${longdate} ${callsite} ${level} ${event-context:item=StrategyId} ${message}";
config.AddTarget("file", fileTarget);
// Step 4. Define rules
LoggingRule rule2 = new LoggingRule("*", NLog.LogLevel.Trace, fileTarget);
config.LoggingRules.Add(rule2);
// Step 5. Activate the configuration
LogManager.Configuration = config;
logger.Debug("startup");
/*************************NLOG CONFIG*****/
you can see the starup printed 6 times and it is called only once in the program at the begining of the program in the Ninjatrader onStartup.
I also have the scoped Global Diagnistoc but i dont think that can cause this to happen
public class ScopedGlobalContext : IDisposable
{
private string n;
private string v;
public ScopedGlobalContext(string name, string value)
{
n = name;
v = value;
NLog.GlobalDiagnosticsContext.Set(n, v);
}
public void Dispose()
{
NLog.GlobalDiagnosticsContext.Remove(n);
}
}
logging nlog
I use Nlog to log and i find that i have 5 entries in my log file for every call made to nLog. How can i fix it?
for eg.
2012-12-23 18:18:19.2465 NinjaTrader.Strategy.LODHOD.OnStartUp Debug startup
2012-12-23 18:18:19.2465 NinjaTrader.Strategy.LODHOD.OnStartUp Debug startup
2012-12-23 18:18:19.2465 NinjaTrader.Strategy.LODHOD.OnStartUp Debug startup
2012-12-23 18:18:19.2465 NinjaTrader.Strategy.LODHOD.OnStartUp Debug startup
2012-12-23 18:18:19.2465 NinjaTrader.Strategy.LODHOD.OnStartUp Debug startup
2012-12-23 18:18:19.2465 NinjaTrader.Strategy.LODHOD.OnStartUp Debug startup
My nLog config is as below
/****CLASS LEVEL VARIABLES***/
// Step 1. Create configuration object
private static LoggingConfiguration config = new LoggingConfiguration();
private static FileTarget fileTarget = new FileTarget();
private static Logger logger = LogManager.GetCurrentClassLogger();
/*** END OF CLASS LEVEL VARIABLES ***/
/*************************NLOG CONFIG*****/
fileTarget.FileName =
"C:\temp\" + Instrument.FullName + "nLog." + DateTime.Now.Ticks + ".log";
fileTarget.Layout =
"${longdate} ${callsite} ${level} ${event-context:item=StrategyId} ${message}";
config.AddTarget("file", fileTarget);
// Step 4. Define rules
LoggingRule rule2 = new LoggingRule("*", NLog.LogLevel.Trace, fileTarget);
config.LoggingRules.Add(rule2);
// Step 5. Activate the configuration
LogManager.Configuration = config;
logger.Debug("startup");
/*************************NLOG CONFIG*****/
you can see the starup printed 6 times and it is called only once in the program at the begining of the program in the Ninjatrader onStartup.
I also have the scoped Global Diagnistoc but i dont think that can cause this to happen
public class ScopedGlobalContext : IDisposable
{
private string n;
private string v;
public ScopedGlobalContext(string name, string value)
{
n = name;
v = value;
NLog.GlobalDiagnosticsContext.Set(n, v);
}
public void Dispose()
{
NLog.GlobalDiagnosticsContext.Remove(n);
}
}
logging nlog
logging nlog
edited Oct 23 '15 at 11:16
superjos
8,208264100
8,208264100
asked Dec 24 '12 at 10:40
junkone
619927
619927
As your rule is called rule2, do you have multiple ones?
– ccellar
Dec 25 '12 at 10:34
no. that is all the code that i have for nLog. i deleted the rule1 but forgot to rename the variables. I am still not sure why it gets printed 6 times
– junkone
Dec 26 '12 at 21:21
Do you have any NLog configuration, either in app.config or in NLog.config? Have you posted all of your NLog configuration code? I see you have a variable, "config", where does it come from?
– wageoghe
Dec 28 '12 at 19:47
these are just class level variables that i was using. i cut and pasted it in the code sample that i have shown.
– junkone
Dec 29 '12 at 20:59
1
In the first code block you have a section (as noted in the comments) called "CLASS LEVEL VARIABLES". Do you have this same code in each class? I ask this because, you should configure NLog exactly once in your application, not once per class. Have you tried making a stripped down program/library to experiment with NLog? It might be easier to figure out what is going on with NLog if you have less stuff going on.
– wageoghe
Jan 2 '13 at 18:06
|
show 3 more comments
As your rule is called rule2, do you have multiple ones?
– ccellar
Dec 25 '12 at 10:34
no. that is all the code that i have for nLog. i deleted the rule1 but forgot to rename the variables. I am still not sure why it gets printed 6 times
– junkone
Dec 26 '12 at 21:21
Do you have any NLog configuration, either in app.config or in NLog.config? Have you posted all of your NLog configuration code? I see you have a variable, "config", where does it come from?
– wageoghe
Dec 28 '12 at 19:47
these are just class level variables that i was using. i cut and pasted it in the code sample that i have shown.
– junkone
Dec 29 '12 at 20:59
1
In the first code block you have a section (as noted in the comments) called "CLASS LEVEL VARIABLES". Do you have this same code in each class? I ask this because, you should configure NLog exactly once in your application, not once per class. Have you tried making a stripped down program/library to experiment with NLog? It might be easier to figure out what is going on with NLog if you have less stuff going on.
– wageoghe
Jan 2 '13 at 18:06
As your rule is called rule2, do you have multiple ones?
– ccellar
Dec 25 '12 at 10:34
As your rule is called rule2, do you have multiple ones?
– ccellar
Dec 25 '12 at 10:34
no. that is all the code that i have for nLog. i deleted the rule1 but forgot to rename the variables. I am still not sure why it gets printed 6 times
– junkone
Dec 26 '12 at 21:21
no. that is all the code that i have for nLog. i deleted the rule1 but forgot to rename the variables. I am still not sure why it gets printed 6 times
– junkone
Dec 26 '12 at 21:21
Do you have any NLog configuration, either in app.config or in NLog.config? Have you posted all of your NLog configuration code? I see you have a variable, "config", where does it come from?
– wageoghe
Dec 28 '12 at 19:47
Do you have any NLog configuration, either in app.config or in NLog.config? Have you posted all of your NLog configuration code? I see you have a variable, "config", where does it come from?
– wageoghe
Dec 28 '12 at 19:47
these are just class level variables that i was using. i cut and pasted it in the code sample that i have shown.
– junkone
Dec 29 '12 at 20:59
these are just class level variables that i was using. i cut and pasted it in the code sample that i have shown.
– junkone
Dec 29 '12 at 20:59
1
1
In the first code block you have a section (as noted in the comments) called "CLASS LEVEL VARIABLES". Do you have this same code in each class? I ask this because, you should configure NLog exactly once in your application, not once per class. Have you tried making a stripped down program/library to experiment with NLog? It might be easier to figure out what is going on with NLog if you have less stuff going on.
– wageoghe
Jan 2 '13 at 18:06
In the first code block you have a section (as noted in the comments) called "CLASS LEVEL VARIABLES". Do you have this same code in each class? I ask this because, you should configure NLog exactly once in your application, not once per class. Have you tried making a stripped down program/library to experiment with NLog? It might be easier to figure out what is going on with NLog if you have less stuff going on.
– wageoghe
Jan 2 '13 at 18:06
|
show 3 more comments
3 Answers
3
active
oldest
votes
up vote
5
down vote
If you have multiple rules that targets for instance file, then you get multiple writes to it.
This thread in the nlog forum suggests to use 'final' to prevent this: nlog-forum.1685105.n2.nabble.com/…
– Stefan Sieber
Apr 21 '16 at 9:32
add a comment |
up vote
2
down vote
I had the same thing happen to me. Several searches lead to other people having the same issue, but no solution. I think this is a bug that happens if you're running multiple threads and/or if the logging is being called inside a Linq query. Remember, Linq does always execute immediately. Although this isn't an answer, it should help you find the source of the problem.
add a comment |
up vote
0
down vote
WhenRepeated-Filter
Matches when the calculated layout has already been logged. Useful if having an aggressive logger, and wants to throttle the output.
Introduced with NLog ver. 4.5
It looks to be the solution introduced by nlog to debounce/throttle log outputs.
WhenRepeated-Filter is a work-around for bad logging behavior in the host-application. It is not meant as work-around for wrongly configured NLog logging-rules (Better just to fix the logging-rule config)
– Rolf Kristensen
Nov 15 at 15:37
add a comment |
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
5
down vote
If you have multiple rules that targets for instance file, then you get multiple writes to it.
This thread in the nlog forum suggests to use 'final' to prevent this: nlog-forum.1685105.n2.nabble.com/…
– Stefan Sieber
Apr 21 '16 at 9:32
add a comment |
up vote
5
down vote
If you have multiple rules that targets for instance file, then you get multiple writes to it.
This thread in the nlog forum suggests to use 'final' to prevent this: nlog-forum.1685105.n2.nabble.com/…
– Stefan Sieber
Apr 21 '16 at 9:32
add a comment |
up vote
5
down vote
up vote
5
down vote
If you have multiple rules that targets for instance file, then you get multiple writes to it.
If you have multiple rules that targets for instance file, then you get multiple writes to it.
answered Nov 4 '13 at 9:32
Johan
4701929
4701929
This thread in the nlog forum suggests to use 'final' to prevent this: nlog-forum.1685105.n2.nabble.com/…
– Stefan Sieber
Apr 21 '16 at 9:32
add a comment |
This thread in the nlog forum suggests to use 'final' to prevent this: nlog-forum.1685105.n2.nabble.com/…
– Stefan Sieber
Apr 21 '16 at 9:32
This thread in the nlog forum suggests to use 'final' to prevent this: nlog-forum.1685105.n2.nabble.com/…
– Stefan Sieber
Apr 21 '16 at 9:32
This thread in the nlog forum suggests to use 'final' to prevent this: nlog-forum.1685105.n2.nabble.com/…
– Stefan Sieber
Apr 21 '16 at 9:32
add a comment |
up vote
2
down vote
I had the same thing happen to me. Several searches lead to other people having the same issue, but no solution. I think this is a bug that happens if you're running multiple threads and/or if the logging is being called inside a Linq query. Remember, Linq does always execute immediately. Although this isn't an answer, it should help you find the source of the problem.
add a comment |
up vote
2
down vote
I had the same thing happen to me. Several searches lead to other people having the same issue, but no solution. I think this is a bug that happens if you're running multiple threads and/or if the logging is being called inside a Linq query. Remember, Linq does always execute immediately. Although this isn't an answer, it should help you find the source of the problem.
add a comment |
up vote
2
down vote
up vote
2
down vote
I had the same thing happen to me. Several searches lead to other people having the same issue, but no solution. I think this is a bug that happens if you're running multiple threads and/or if the logging is being called inside a Linq query. Remember, Linq does always execute immediately. Although this isn't an answer, it should help you find the source of the problem.
I had the same thing happen to me. Several searches lead to other people having the same issue, but no solution. I think this is a bug that happens if you're running multiple threads and/or if the logging is being called inside a Linq query. Remember, Linq does always execute immediately. Although this isn't an answer, it should help you find the source of the problem.
answered Feb 20 '13 at 16:45
ATL_DEV
1,62742144
1,62742144
add a comment |
add a comment |
up vote
0
down vote
WhenRepeated-Filter
Matches when the calculated layout has already been logged. Useful if having an aggressive logger, and wants to throttle the output.
Introduced with NLog ver. 4.5
It looks to be the solution introduced by nlog to debounce/throttle log outputs.
WhenRepeated-Filter is a work-around for bad logging behavior in the host-application. It is not meant as work-around for wrongly configured NLog logging-rules (Better just to fix the logging-rule config)
– Rolf Kristensen
Nov 15 at 15:37
add a comment |
up vote
0
down vote
WhenRepeated-Filter
Matches when the calculated layout has already been logged. Useful if having an aggressive logger, and wants to throttle the output.
Introduced with NLog ver. 4.5
It looks to be the solution introduced by nlog to debounce/throttle log outputs.
WhenRepeated-Filter is a work-around for bad logging behavior in the host-application. It is not meant as work-around for wrongly configured NLog logging-rules (Better just to fix the logging-rule config)
– Rolf Kristensen
Nov 15 at 15:37
add a comment |
up vote
0
down vote
up vote
0
down vote
WhenRepeated-Filter
Matches when the calculated layout has already been logged. Useful if having an aggressive logger, and wants to throttle the output.
Introduced with NLog ver. 4.5
It looks to be the solution introduced by nlog to debounce/throttle log outputs.
WhenRepeated-Filter
Matches when the calculated layout has already been logged. Useful if having an aggressive logger, and wants to throttle the output.
Introduced with NLog ver. 4.5
It looks to be the solution introduced by nlog to debounce/throttle log outputs.
answered Nov 13 at 20:18
willll
1,2351320
1,2351320
WhenRepeated-Filter is a work-around for bad logging behavior in the host-application. It is not meant as work-around for wrongly configured NLog logging-rules (Better just to fix the logging-rule config)
– Rolf Kristensen
Nov 15 at 15:37
add a comment |
WhenRepeated-Filter is a work-around for bad logging behavior in the host-application. It is not meant as work-around for wrongly configured NLog logging-rules (Better just to fix the logging-rule config)
– Rolf Kristensen
Nov 15 at 15:37
WhenRepeated-Filter is a work-around for bad logging behavior in the host-application. It is not meant as work-around for wrongly configured NLog logging-rules (Better just to fix the logging-rule config)
– Rolf Kristensen
Nov 15 at 15:37
WhenRepeated-Filter is a work-around for bad logging behavior in the host-application. It is not meant as work-around for wrongly configured NLog logging-rules (Better just to fix the logging-rule config)
– Rolf Kristensen
Nov 15 at 15:37
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f14020208%2fduplicate-log-entries-nlog%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
As your rule is called rule2, do you have multiple ones?
– ccellar
Dec 25 '12 at 10:34
no. that is all the code that i have for nLog. i deleted the rule1 but forgot to rename the variables. I am still not sure why it gets printed 6 times
– junkone
Dec 26 '12 at 21:21
Do you have any NLog configuration, either in app.config or in NLog.config? Have you posted all of your NLog configuration code? I see you have a variable, "config", where does it come from?
– wageoghe
Dec 28 '12 at 19:47
these are just class level variables that i was using. i cut and pasted it in the code sample that i have shown.
– junkone
Dec 29 '12 at 20:59
1
In the first code block you have a section (as noted in the comments) called "CLASS LEVEL VARIABLES". Do you have this same code in each class? I ask this because, you should configure NLog exactly once in your application, not once per class. Have you tried making a stripped down program/library to experiment with NLog? It might be easier to figure out what is going on with NLog if you have less stuff going on.
– wageoghe
Jan 2 '13 at 18:06