简体   繁体   中英

Serilog Integration with .net c# class library

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?

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");
            }
        }
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM