Serilog Integration with .net c# class library
up vote
0
down vote
favorite
I am working on an application that was developed using c++ and c#. Main executable will be in c++ and c# dll(functions in the c# dll) will be called using COM interface from c++. However no executable at c# side , every projects are class library. I planned to use serilog framework for c# side logging. I am not able to do that since no main executable is not there at c# side.
In my case whether any possibilities are there to use serilog framework at c# side?
c# serilog
|
show 4 more comments
up vote
0
down vote
favorite
I am working on an application that was developed using c++ and c#. Main executable will be in c++ and c# dll(functions in the c# dll) will be called using COM interface from c++. However no executable at c# side , every projects are class library. I planned to use serilog framework for c# side logging. I am not able to do that since no main executable is not there at c# side.
In my case whether any possibilities are there to use serilog framework at c# side?
c# serilog
You can use constructor for instantiateLog.Logger
in your class library or you can use inheritance for that if you are separating it in a module.
– Hardik
Nov 12 at 5:08
@Hardik Actually I was tried to initiate Log.Logger in constructor of class library class , it was not succeed. Log.Logger initiate itself failing i was not able to catch the failure.
– Aishwarya
Nov 12 at 6:03
Is there any error? have to try to log information just after creating of instance?
– Hardik
Nov 12 at 6:27
I was initializing Log.Logger = new LoggerConfiguration().WriteTo.Console().CreateLogger(); in constructor of a class and i have writing information into file Before and After the above line of code . When i am having the above line of code Both prints are not printed that is before and also after. When i am removing the above line of code both prints are printed .I added above line of code in try catch and in catch also i have added some prints and that is also not printed.
– Aishwarya
Nov 12 at 6:40
So, Is it working now?
– Hardik
Nov 12 at 6:43
|
show 4 more comments
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I am working on an application that was developed using c++ and c#. Main executable will be in c++ and c# dll(functions in the c# dll) will be called using COM interface from c++. However no executable at c# side , every projects are class library. I planned to use serilog framework for c# side logging. I am not able to do that since no main executable is not there at c# side.
In my case whether any possibilities are there to use serilog framework at c# side?
c# serilog
I am working on an application that was developed using c++ and c#. Main executable will be in c++ and c# dll(functions in the c# dll) will be called using COM interface from c++. However no executable at c# side , every projects are class library. I planned to use serilog framework for c# side logging. I am not able to do that since no main executable is not there at c# side.
In my case whether any possibilities are there to use serilog framework at c# side?
c# serilog
c# serilog
asked Nov 12 at 3:32
Aishwarya
66
66
You can use constructor for instantiateLog.Logger
in your class library or you can use inheritance for that if you are separating it in a module.
– Hardik
Nov 12 at 5:08
@Hardik Actually I was tried to initiate Log.Logger in constructor of class library class , it was not succeed. Log.Logger initiate itself failing i was not able to catch the failure.
– Aishwarya
Nov 12 at 6:03
Is there any error? have to try to log information just after creating of instance?
– Hardik
Nov 12 at 6:27
I was initializing Log.Logger = new LoggerConfiguration().WriteTo.Console().CreateLogger(); in constructor of a class and i have writing information into file Before and After the above line of code . When i am having the above line of code Both prints are not printed that is before and also after. When i am removing the above line of code both prints are printed .I added above line of code in try catch and in catch also i have added some prints and that is also not printed.
– Aishwarya
Nov 12 at 6:40
So, Is it working now?
– Hardik
Nov 12 at 6:43
|
show 4 more comments
You can use constructor for instantiateLog.Logger
in your class library or you can use inheritance for that if you are separating it in a module.
– Hardik
Nov 12 at 5:08
@Hardik Actually I was tried to initiate Log.Logger in constructor of class library class , it was not succeed. Log.Logger initiate itself failing i was not able to catch the failure.
– Aishwarya
Nov 12 at 6:03
Is there any error? have to try to log information just after creating of instance?
– Hardik
Nov 12 at 6:27
I was initializing Log.Logger = new LoggerConfiguration().WriteTo.Console().CreateLogger(); in constructor of a class and i have writing information into file Before and After the above line of code . When i am having the above line of code Both prints are not printed that is before and also after. When i am removing the above line of code both prints are printed .I added above line of code in try catch and in catch also i have added some prints and that is also not printed.
– Aishwarya
Nov 12 at 6:40
So, Is it working now?
– Hardik
Nov 12 at 6:43
You can use constructor for instantiate
Log.Logger
in your class library or you can use inheritance for that if you are separating it in a module.– Hardik
Nov 12 at 5:08
You can use constructor for instantiate
Log.Logger
in your class library or you can use inheritance for that if you are separating it in a module.– Hardik
Nov 12 at 5:08
@Hardik Actually I was tried to initiate Log.Logger in constructor of class library class , it was not succeed. Log.Logger initiate itself failing i was not able to catch the failure.
– Aishwarya
Nov 12 at 6:03
@Hardik Actually I was tried to initiate Log.Logger in constructor of class library class , it was not succeed. Log.Logger initiate itself failing i was not able to catch the failure.
– Aishwarya
Nov 12 at 6:03
Is there any error? have to try to log information just after creating of instance?
– Hardik
Nov 12 at 6:27
Is there any error? have to try to log information just after creating of instance?
– Hardik
Nov 12 at 6:27
I was initializing Log.Logger = new LoggerConfiguration().WriteTo.Console().CreateLogger(); in constructor of a class and i have writing information into file Before and After the above line of code . When i am having the above line of code Both prints are not printed that is before and also after. When i am removing the above line of code both prints are printed .I added above line of code in try catch and in catch also i have added some prints and that is also not printed.
– Aishwarya
Nov 12 at 6:40
I was initializing Log.Logger = new LoggerConfiguration().WriteTo.Console().CreateLogger(); in constructor of a class and i have writing information into file Before and After the above line of code . When i am having the above line of code Both prints are not printed that is before and also after. When i am removing the above line of code both prints are printed .I added above line of code in try catch and in catch also i have added some prints and that is also not printed.
– Aishwarya
Nov 12 at 6:40
So, Is it working now?
– Hardik
Nov 12 at 6:43
So, Is it working now?
– Hardik
Nov 12 at 6:43
|
show 4 more comments
1 Answer
1
active
oldest
votes
up vote
0
down vote
try to create logger only.
and then just next line try to log something.
public class EServerAPI : IEServerAPI
{
public EServerAPI()
{
try
{
System.IO.File.WriteAllText("E:\InitLog.txt", "Going to initialize logger.");
Log.Logger = new LoggerConfiguration()
.WriteTo.File("logs\myapp.txt", rollingInterval: RollingInterval.Day)
.CreateLogger();
Log.Information("Hello, world!");
System.IO.File.WriteAllText("E:\InitLogEnd.txt", "Initialize logger has end.");
}
catch(Exception ex)
{
System.IO.File.WriteAllText("E:\exception.txt",ex.Message);
}
catch
{
System.IO.File.WriteAllText("E:\unhandExce.txt","unhandled excpetion occur");
}
}
}
I have tried the above code again the same it was not working .
– Aishwarya
Nov 12 at 8:45
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
try to create logger only.
and then just next line try to log something.
public class EServerAPI : IEServerAPI
{
public EServerAPI()
{
try
{
System.IO.File.WriteAllText("E:\InitLog.txt", "Going to initialize logger.");
Log.Logger = new LoggerConfiguration()
.WriteTo.File("logs\myapp.txt", rollingInterval: RollingInterval.Day)
.CreateLogger();
Log.Information("Hello, world!");
System.IO.File.WriteAllText("E:\InitLogEnd.txt", "Initialize logger has end.");
}
catch(Exception ex)
{
System.IO.File.WriteAllText("E:\exception.txt",ex.Message);
}
catch
{
System.IO.File.WriteAllText("E:\unhandExce.txt","unhandled excpetion occur");
}
}
}
I have tried the above code again the same it was not working .
– Aishwarya
Nov 12 at 8:45
add a comment |
up vote
0
down vote
try to create logger only.
and then just next line try to log something.
public class EServerAPI : IEServerAPI
{
public EServerAPI()
{
try
{
System.IO.File.WriteAllText("E:\InitLog.txt", "Going to initialize logger.");
Log.Logger = new LoggerConfiguration()
.WriteTo.File("logs\myapp.txt", rollingInterval: RollingInterval.Day)
.CreateLogger();
Log.Information("Hello, world!");
System.IO.File.WriteAllText("E:\InitLogEnd.txt", "Initialize logger has end.");
}
catch(Exception ex)
{
System.IO.File.WriteAllText("E:\exception.txt",ex.Message);
}
catch
{
System.IO.File.WriteAllText("E:\unhandExce.txt","unhandled excpetion occur");
}
}
}
I have tried the above code again the same it was not working .
– Aishwarya
Nov 12 at 8:45
add a comment |
up vote
0
down vote
up vote
0
down vote
try to create logger only.
and then just next line try to log something.
public class EServerAPI : IEServerAPI
{
public EServerAPI()
{
try
{
System.IO.File.WriteAllText("E:\InitLog.txt", "Going to initialize logger.");
Log.Logger = new LoggerConfiguration()
.WriteTo.File("logs\myapp.txt", rollingInterval: RollingInterval.Day)
.CreateLogger();
Log.Information("Hello, world!");
System.IO.File.WriteAllText("E:\InitLogEnd.txt", "Initialize logger has end.");
}
catch(Exception ex)
{
System.IO.File.WriteAllText("E:\exception.txt",ex.Message);
}
catch
{
System.IO.File.WriteAllText("E:\unhandExce.txt","unhandled excpetion occur");
}
}
}
try to create logger only.
and then just next line try to log something.
public class EServerAPI : IEServerAPI
{
public EServerAPI()
{
try
{
System.IO.File.WriteAllText("E:\InitLog.txt", "Going to initialize logger.");
Log.Logger = new LoggerConfiguration()
.WriteTo.File("logs\myapp.txt", rollingInterval: RollingInterval.Day)
.CreateLogger();
Log.Information("Hello, world!");
System.IO.File.WriteAllText("E:\InitLogEnd.txt", "Initialize logger has end.");
}
catch(Exception ex)
{
System.IO.File.WriteAllText("E:\exception.txt",ex.Message);
}
catch
{
System.IO.File.WriteAllText("E:\unhandExce.txt","unhandled excpetion occur");
}
}
}
answered Nov 12 at 8:28
Hardik
1,3011219
1,3011219
I have tried the above code again the same it was not working .
– Aishwarya
Nov 12 at 8:45
add a comment |
I have tried the above code again the same it was not working .
– Aishwarya
Nov 12 at 8:45
I have tried the above code again the same it was not working .
– Aishwarya
Nov 12 at 8:45
I have tried the above code again the same it was not working .
– Aishwarya
Nov 12 at 8:45
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%2f53255616%2fserilog-integration-with-net-c-sharp-class-library%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
You can use constructor for instantiate
Log.Logger
in your class library or you can use inheritance for that if you are separating it in a module.– Hardik
Nov 12 at 5:08
@Hardik Actually I was tried to initiate Log.Logger in constructor of class library class , it was not succeed. Log.Logger initiate itself failing i was not able to catch the failure.
– Aishwarya
Nov 12 at 6:03
Is there any error? have to try to log information just after creating of instance?
– Hardik
Nov 12 at 6:27
I was initializing Log.Logger = new LoggerConfiguration().WriteTo.Console().CreateLogger(); in constructor of a class and i have writing information into file Before and After the above line of code . When i am having the above line of code Both prints are not printed that is before and also after. When i am removing the above line of code both prints are printed .I added above line of code in try catch and in catch also i have added some prints and that is also not printed.
– Aishwarya
Nov 12 at 6:40
So, Is it working now?
– Hardik
Nov 12 at 6:43